Maven sets up a dependency mediation strategy for the newest,

Can I configure Maven to choose the “latest” conflict dependency rather than the “closest” one?

"Newest" is the default for Ivy and other smart dependency managers, see http://ant.apache.org/ivy/history/2.2.0/settings/conflict-managers.html

I believe that the “closest” strategy is rarely what I want.

I am using Maven 3.3.3, but if necessary I can switch versions.

I know how to override Maven's choice for individual conflicts, but I would prefer to change the default so that I don't have to detect and fix each conflict one at a time.

(See Maven docs in the Mediation Dependency section)

+7
java maven
source share
2 answers

Can I configure Maven to automatically use the “latest” version of the dependency instead of the “closest” version when resolving version conflicts?

No , you cannot set up a Maven dependency mediation strategy for everything except the closest.

Adding custom dependency mediation strategies were proposed before , but were eventually abandoned, as the proposal included a change in POM XSD, which was not in years.

Why does Maven use the closest default strategy?

The closest strategy is endorsed by Maven for two reasons:

  • Simple redefinition of individual conflicts : for any specific conflict you can specify your version in your own POM, and this version will be the closest.
  • Playable builds . This would indeed be the result of version ranges anywhere in your dependency graph, but the “latest” mediation strategy will undoubtedly increase the effect of any version range on assembly reproducibility.

But I really need a different addiction mediation strategy. What can I do?

These are your best options:

+2
source share

You can also use the “requireUpperBoundDeps” rule for the Maven “enforcer” plugin, which will not directly implement the “latest wins,” conflict resolution policies, but will ensure that the end result is the same. You will need to manually add the <exclusions> or <dependencyManagement> transitive dependency rules to your POM to select the newest dependency in each conflict, but at least you will be sure that the end result is the “newest wins”.

  <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-enforcer-plugin</artifactId> <version>1.4.1</version> <executions> <execution> <id>enforce</id> <configuration> <rules> <requireUpperBoundDeps /> </rules> </configuration> <goals> <goal>enforce</goal> </goals> </execution> </executions> </plugin> 
+1
source share

All Articles