javamavendependenciesdependency-tree

On which level of the maven dependency tree are dependencies from the parent project


I have a parent pom which has a dependency to third party jar A with version 1.0. Then I have a child project which inherits from the parent pom. This child project defines a dependency to library B which itself has the dependency to the third party jar A with version 1.1.

Does the dependency tree look like this(and therefore version 1.0 is pulled in):

Child->A(version 1.0) Child->B->A(version 1.1)

On which level of the dependency tree are the dependencies of the parent POM?


Solution

  • Before dependencies are resolved, the parent and child POM are first combined into an "effective POM". You can display the effective POM using mvnhelp:effective-pom. Hence your dependency tree becomes:

      (Effective POM) -> A:1.0
      (Effective POM) -> B     -> A:1.1
    

    The effect is the same as if you had declared the A:1.0 dependency in the child POM. Since dependencies closer to the root "win" in Maven, A:1.0 is used.

    Also, if both the parent and child POM declare a dependency to the same module, the version specified by the child overrides the one specified by the parent (= becomes the version in the effective POM).