What if I have two versions of the same dependency: one in parent pom, another in child pom? How does Maven resolve it — assuming no <dependencyManagement>
?
Please back it up with a doc quote, if possible.
<!-- parent pom -->
<dependency>
<groupId>com.example</groupId>
<artifactId>some-artifact</artifactId>
<version>1.1</version>
</dependency>
<!-- child pom -->
<dependency>
<groupId>com.example</groupId>
<artifactId>some-artifact</artifactId>
<version>1.0</version>
</dependency>
I found this in the Maven documentation
Dependency mediation - this determines what version of an artifact will be chosen when multiple versions are encountered as dependencies. Maven picks the "nearest definition". That is, it uses the version of the closest dependency to your project in the tree of dependencies. You can always guarantee a version by declaring it explicitly in your project's POM. Note that if two dependency versions are at the same depth in the dependency tree, the first declaration wins.
However, save for this brief mention
In general, all dependencies of those projects are used in your project, as are any that the project inherits from its parents, or from its dependencies, and so on.
it doesn't mention parent poms explicitly, so I'm not sure whether it describes my case as well.
What if I have two versions of the same dependency: one in parent pom, another in child pom? How does Maven resolve it — assuming no <dependencyManagement>
?
Please back it up with a doc quote, if possible.
<!-- parent pom -->
<dependency>
<groupId>com.example</groupId>
<artifactId>some-artifact</artifactId>
<version>1.1</version>
</dependency>
<!-- child pom -->
<dependency>
<groupId>com.example</groupId>
<artifactId>some-artifact</artifactId>
<version>1.0</version>
</dependency>
I found this in the Maven documentation
Dependency mediation - this determines what version of an artifact will be chosen when multiple versions are encountered as dependencies. Maven picks the "nearest definition". That is, it uses the version of the closest dependency to your project in the tree of dependencies. You can always guarantee a version by declaring it explicitly in your project's POM. Note that if two dependency versions are at the same depth in the dependency tree, the first declaration wins.
However, save for this brief mention
In general, all dependencies of those projects are used in your project, as are any that the project inherits from its parents, or from its dependencies, and so on.
it doesn't mention parent poms explicitly, so I'm not sure whether it describes my case as well.
Share Improve this question edited 2 days ago Cagepi asked Feb 18 at 3:09 CagepiCagepi 1911 silver badge7 bronze badges 3 |1 Answer
Reset to default 0Usually, you should not put dependencies into the parent POM.
I guess that the parent POM dependency wins. But this is something that you could try for yourself. You can also look at the effective POM. The problem is probably equivalent to the question: What happens if you declare the same dependency twice?
I doubt that there is any documentation about this except the source code itself.
dependencyManagement
or not could change the result for instance. – Gaël J Commented 2 days agomvn dependency:tree
which one is picked up. (Though that won't necessarily explain why) – Gaël J Commented 2 days ago