fastcodejava
fastcodejava

Reputation: 41087

Maven including older version of spring

I have a maven project in eclipse with m2e plugin. Dependency hierarchy is showing it is omitting spring 3.2.3 in place of 3.0.0.RELEASE as shown below. How to do it otherwise? Should it not omit the older version and keep the latest?

enter image description here

Upvotes: 0

Views: 216

Answers (1)

saurav
saurav

Reputation: 3462

Maven works on the principle of nearest wins strategy while resolving the dependency conflicts , that means whichever version it finds nearer in the tree , it will take that version and ignore the other versions.

In your case when you can run -

mvn dependency:tree -Dverbose -Dincludes=spring-aop

You will notice that in the tree hierarchy version 3.0.0 is coming earlier in comparison to version 3.2.3 , so that's why it is taking version 3.0.0 version for resolving the dependency.

Solution : As a recommended solution to these types of problem is have a proper dependency management in your parent pom.xml file. Like in your case you can have something lik e this :

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>com.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>3.2.3</version>
      </dependency>
   <dependencies>
  </dependencyManagement>

Now no matter what whenever Maven try to resolve the version for spring-aop , it will always consult the dependency management and will use the version defined under dependencyManagement.

For more you can refer here on my blog: how maven resolves dependency conflicts

Upvotes: 3

Related Questions