Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams
  • I faced a problem with dependency:tree. It troubled me a few days. I defined solr-solrj with version 6.6.0 in my pom.xml in one of my modules named A as below: <dependency> <groupId>org.apache.solr</groupId> <artifactId>solr-solrj</artifactId> <version>6.6.0</version> </dependency>

  • Another module named B dependencies on module A. when I run mvn dependency:tree -Dverbose -Dincludes=org.apache.solr:solr-solrj , the console appears org.apache.solr:solr-solrj:jar:5.5.3:compile (version managed from 6.6.0) . I find all the pom.xml, I haven't defined the 5.5.3 version. And I haven't found any jar dependencies on 5.5.3 version transitively in my project.

  • What's the meaning of 5.5.3:compile (version managed from 6.6.0 ? And why 5.5.3 version appeared in my project?

  • Either the pom for module B or the parent pom for module B includes a <dependencyManagement> section. Dependency management is used in maven to centralize the versions used for jars. It is likely overriding the version of solr-solrj you defined to be version 5.5.3. Dependency management functions in two main ways. You are probably experiencing what is described in section 2. Please see the conclusion for a summary specific to your question.

    1. It is a central place for defining versions of dependencies.

    So when an artifact version is defined in the <dependencyManagement> section you can declare the dependency in your pom without defining the version, and the version defined in <dependencyManagement> will be used automatically.

    Example 1

    Let's say your parent pom defined the following

    <dependencyManagement>
      <dependencies>
        <dependency>
          <groupId>com.mememe</groupId>
          <artifactId>mylib</artifactId>
          <version>1.1.12</version>
        </dependency>
      </dependencies>
    </dependencyManagement>
    

    Then if you define the following in your pom

    <dependencies>
      <dependency>
        <groupId>com.mememe</groupId>
        <artifactId>mylib</artifactId>
      </dependency>
    </dependencies>
    

    Your project will automatically use version 1.1.12 as defined in the <dependencyManagement> section of your parent pom.

    2. Overriding the versions of transitive dependencies.

    If you have an artifact version defined in your <dependencyManagement> and one of your dependencies has a transitive dependency on the same artifact, the version of the artifact defined in your <dependencyManagement> section is used automatically.

    Example 2

    Let's say this artifact

    <dependency>
      <groupId>com.youyou</groupId>
      <artifactId>yourlib</artifactId>
      <version>3.0.0</version>
    </dependency>
    

    Has this transitive dependency

    <dependency>
      <groupId>com.morestuff</groupId>
      <artifactId>morelib</artifactId>
      <version>2.0.0</version>
    </dependency>
    

    Now let's say our parent pom defines this <dependencyManagement> section

    <dependencyManagement>
      <dependencies>
        <dependency>
          <groupId>com.morestuff</groupId>
          <artifactId>morelib</artifactId>
          <version>2.5.2</version>
        </dependency>
      </dependencies>
    </dependencyManagement>
    

    Then if you define this dependency in your pom

    <dependency>
      <groupId>com.youyou</groupId>
      <artifactId>yourlib</artifactId>
      <version>3.0.0</version>
    </dependency>
    

    Maven will override yourlib's dependency on morelib version 2.0.0 with morelib version 2.5.2.

    Conclusion

    Specific to your question, someone has defined a <dependencyManagement> section like the following in the pom or parent pom of module B:

    <dependencyManagement>
      <dependencies>
        <dependency>
          <groupId>org.apache.solr</groupId>
          <artifactId>solr-solrj</artifactId>
          <version>5.5.3</version>
        </dependency>
      </dependencies>
    </dependencyManagement>
    

    Since solr-solrj is a dependency of module A and mondule A is a dependency of module B. Dependency management is overriding the version of solr-solrj to be 5.5.3 . You should speak with the person who added this dependencyManagement configuration in your project, there is likely a good reason why they only wanted version 5.5.3 to be used.

    See more details in the official maven docs here.

    yeah, you're right. I found version 5.5.3 defined in spring-boot-dependencies pom.xml. And spring-boot-dependencies defined in module B parents' dependencyManagement. – 刘同彬 Mar 7, 2018 at 11:31 Thanks for such a good explanation, saved my time, I also found dependency management which is causing this. – Hars Dec 15, 2021 at 10:10 I've a similar problem where i see ` org.freemarker:freemarker:jar:2.3.31:compile (version managed from 2.3.32)` but there is no dependencyManagement section in any of my poms – Krittam Kothari Apr 12 at 7:13

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.