Gunnar
Gunnar

Reputation: 413

Maven resolves wrong dependency version

Our warfile contains not the expected SNAPSHOT-Version of a jarfile, it contains an older release version via another dependency.

Simplified dependency:tree

war-x.x.x-SNAPSHOT
\- jar1-x.x.x-SNAPSHOT
   +- jar2-x.x.x
   |  +- problemjar-x.x.x
   +- jar3-x.x.x-SNAPSHOT

jar3-x.x.x-SNAPSHOT has a dependency "problemjar-x.x.y-SNAPSHOT" (newer version), but the war project build (and the dependency:tree) contains "problemjar-x.x.x" from "jar2-x.x.x".

For now, we "exclude" "problemjar-x.x.x" for "jar2-x.x.x".

But it would be nice to know the reason for this behaviour, IMHO the exclusion is just a workaround.

Notes:

edit: project structure

war and jar1 are children of one parent pom, the simplified dependency:tree is from the war project which has the jar1 project as a dependency. The others are normal/external dependencies, which applies to jar1 too as seen from the war project.

Upvotes: 1

Views: 3187

Answers (2)

J Fabian Meier
J Fabian Meier

Reputation: 35785

Maven does not take the newest version from the dependency tree.

It takes the nearest version, and in your case this is the first it encounters.

If you want to force Maven to take a specific version, it is better to use <dependencyManagement> instead of exclusions.

Upvotes: 3

Essex Boy
Essex Boy

Reputation: 7940

Make sure of the following:

1) Each child module should take it's version from it's parent, i.e. do not have a <version> tag only a <parent> tag that contains a version.

2) When you call the dependency from the same project always do it as follows:

<version>${project.version}</version>

Upvotes: 0

Related Questions