Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven dependency conflict - Higher version

I have a project that have some dependencies that are the same but with different versions. Example:

  • commons-logging-1.0.4.jar
  • commons-logging-1.1.1.jar (omitted for conflict with 1.0.4)

Is there a configuration that allows me to force maven to always get the higher version of the dependencies with conflict?

like image 593
diegocmaia Avatar asked Jul 13 '26 23:07

diegocmaia


2 Answers

force maven to always get the higher version

You do not want to do that. There might be transitative dependecies that depend on the older versions that have different API from the newer versions.

What you wish to do is solve your dependecy problems at the source. Find out what needs an older dependecy and why. The see what you can do to resolve the conflict.

If the API is unchanged, you can declare the dependecies explicitely and exclude the old transitative, ex here we exclude xml-apis from xerces:

<dependency>
    <groupId>xerces</groupId>
    <artifactId>xercesImpl</artifactId>
    <version>2.11.0</version>
    <scope>compile</scope>
    <exclusions>
        <exclusion> 
            <groupId>xml-apis</groupId>
            <artifactId>xml-apis</artifactId>
        </exclusion>
    </exclusions> 
</dependency>

Using the above logic you can then declare the versions you need of the library. However, be careful not to end up with non-compiling code due to api changes between library versions.

like image 89
john Avatar answered Jul 16 '26 15:07

john


http://maven.apache.org/enforcer/enforcer-rules/requireUpperBoundDeps.html forces you to use and/or specify the latest version of all dependencies. So it's not an automatic get, but it matches your requirements.

like image 20
Robert Scholte Avatar answered Jul 16 '26 16:07

Robert Scholte



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!