1

I am quite confused about how does maven handle the transitive dependencies and how does it write to the classpath.

Say if I have two paths for E (A,B,C,D,E are ejb):
1. A<---B<---E (E dependent(comile) on B which dependent on A)
2. A<---C<---D<---E (all the dependencies are compile dependencies)

Question is: How does E built, and which artifacts are in E's classpath(META-INF).

Thanks a lot!

almightyGOSU
  • 3,731
  • 6
  • 31
  • 41
Yvonne Ye
  • 21
  • 3

1 Answers1

1

Maven will use the "nearest definition" in determining which version of dependency E to use in your build. From the official Maven documentation:

"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

In your example:

1. A <--- B <--- E 1.0
2. A <--- C <--- D <--- E 2.0

The 1.0 version of dependency E will be used, because when building A the path is shorter to this version.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
  • Thanks, but I am not talking about version conflict, as I discovered, A,B,C,D are all in E's manifest classpath. I am wondering if I exclude them from the classpath, will E still compile? And is there a way to exclude them from the classpath? – Yvonne Ye Jun 03 '15 at 08:15
  • `E` may still compile if your `.m2` directory contains the dependencies which it needs. If you exclude them from the classpath, then it should not compile. – Tim Biegeleisen Jun 03 '15 at 15:59