J Fabian Meier
J Fabian Meier

Reputation: 35903

Disable Maven dependency mediation

As I don't trust Maven to pick the "best" version for me in dependency mediation, I would like to fail the build if there is a version conflict that is not explicitly fixed in the pom (usually by using dependencyManagement).

The dependencyConvergence rule of the enforcer plugin seemed to be what I was looking for, but unfortunately, it cannot handle *-exludes (https://issues.apache.org/jira/browse/MENFORCER-195), so I cannot really use it.

Is there any other way to stop Maven from applying the "nearest dependency wins rule" but make the owner of the pom decide which version to use?

Upvotes: 14

Views: 1315

Answers (2)

kriegaex
kriegaex

Reputation: 67477

You can use Maven Enforcer Plugin and fail the build if dependencyConvergence is violated. Give it a shot and see if it does what you want.

Update: Sorry, I just noticed that you tried and are having a problem with excludes. Have you tried to build the plugin with the pull request from the linked ticket and see if it fixes the problem for you?

Upvotes: 3

Joachim Rohde
Joachim Rohde

Reputation: 6045

You can define explicitly which version Maven should use by using dependency version ranges.

Basically you just need to surround your version with round brackets (exclusive quantifier) or square brackets (inclusive quantifier).

For example:

<version>[4.2]</version>

would mean: use exactly version 4.2 and nothing else.

Or:

<version>[4.2,)</version>

would mean: use version 4.2 or higher.

Or:

<version>(,4.2]</version>

would mean: use a version below or exactly 4.2.

Upvotes: 1

Related Questions