2

Let's assume we have a Project A.

  • Project A has a dependency on Project B version 1.0
  • Project A has a dependency on Project C version 2.0
  • Project C (version 2.0) has a dependency on Project B version 2.0

In this case, how would Maven resolve the conflict?

Chris Halcrow
  • 28,994
  • 18
  • 176
  • 206
erolkaya84
  • 1,769
  • 21
  • 28
  • I'm not satisfied the question. According to http://stackoverflow.com/help/how-to-ask, you should "Explain how you encountered the problem you're trying to solve, and any difficulties that have prevented you from solving it yourself." I don't see any dififculties to prevent solve issue yourself. – michaldo Aug 10 '16 at 08:14
  • Is this a multi module build? – khmarbaise Aug 10 '16 at 08:22
  • @khmarbaise no. I have project B and project C as a dependency in the pom.xml of project A. – erolkaya84 Aug 10 '16 at 08:26

2 Answers2

3

I found this explanation and it was really helpful to me.

Nearest definition means that the version used will be the closest one to your project in the tree of dependencies,

eg. if dependencies for A, B, and C are defined as A -> B -> C -> D 2.0 and A -> E -> D 1.0, then D 1.0 will be used when building A because the path from A to D through E is shorter. You could explicitly add a dependency to D 2.0 in A to force the use of D 2.0

Community
  • 1
  • 1
erolkaya84
  • 1,769
  • 21
  • 28
2

It'd build with Project B v 1.0

You can use http://maven.apache.org/plugins/maven-dependency-plugin/examples/resolving-conflicts-using-the-dependency-tree.html to see, that it omitted B 2.0 cause 1.0 is nearer.

from page above:

by default Maven resolves version conflicts with a nearest-wins strategy.

Output'd be something like that:

[INFO] [dependency:tree]
[INFO] Project A
[INFO] +- Project-B:jar:1.0:compile
[INFO] \- Project-C:jar:2.0:compile
[INFO]    \- (Project-B:jar:2.0:compile - ommited for conflicts with 1.0)
Nickname0222022022
  • 577
  • 1
  • 4
  • 22
  • Old but working link: https://maven.apache.org/plugins-archives/maven-dependency-plugin-2.8/examples/resolving-conflicts-using-the-dependency-tree.html – Leponzo Mar 15 '22 at 15:17