Reputation: 49077
When I download Hibernate entitymanager from http://mvnrepository.com/artifact/org.hibernate you see that it also depends on the validator in version 4.2. However the latest is 4.3. If I add another dependency on only the validator would I end up using 4.3 or 4.2? How are you supposed to deal with such scenarios? Should you manually override? or just use the dependencies that the "main" dependency relies on?
Upvotes: 1
Views: 77
Reputation: 7952
According to Introduction to the Dependency Mechanism
Dependency mediation - this determines what version of a dependency will be used when multiple versions of an artifact are encountered. Currently, Maven 2.0 only supports using the "nearest definition" which means that it will use 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.
So to answer your original question:
If I add another dependency on only the validator would I end up using 4.3 or 4.2?
if you explicitly add a dependency with version 4.3 it should choose 4.3 since anything in your pom is "nearer" than any transitive dependency.
How are you supposed to deal with such scenarios? Should you manually override? or just use the dependencies that the "main" dependency relies on?
If I have even the slightest doubt about which dependency to use, I pick the latest/greatest stable version and explicitly add it my pom. But that's just me.
Upvotes: 4