Hi Unjars (short for unjargoners),
Hopefully, you are coming over from my blog post on WTF in Maven? and Maven-Safe-Haven. If not, do visit them and get back here so you can easily connect the dots.
In this sample project I've created a project structure as below
Its a multi module maven project, consisting of
- maven-safe-haven - The parent
- lib-b - Child Module dependent on gson-utils, a library from json-mystique
- lib-a - Child Module dependent on lib-b and gson-utils, a library from json-mystique
Now, if you recollect our discussion on my blog, we were discussing conflict resolution and picked a scenario as below
The library names used their was generic. Considering the current project structure, the updated scenario would like below with explicit library names and versions
For simplicity, the maven projects are packaged as poms and not jars, since we are more interested in understanding maven's conflict resolution rather than any core functionality.
Great then, let's start grinding, shall we?
-
Step 1
Import the project in some IDE (Eclipse, STS, etc) -
Step 2
Open the pom.xml of lib-a module -
Step 3
Choose the Dependency Hierarchy Tab in STS/Eclipse.
Note - Alternatively, you can run the maven command "mvn dependency:tree" and see the maven dependency tree on the console. The UI look is much better and easier to understand, so I'm going ahead and using the STS UI
The dependency Hierarchy Tab will be as below. The left pane shows the dependency hierarchy and the right pane shows the final resolved jars with versions in the classpath
- Step 4
On the top right corner, type lib-b in the filter checkbox. You will see the tab updated as below. This is straight forward. No magic here. There is only one version lib-b, so the version 0.0.1 is shown
- Step5
Now filter for gson-utils. The dependency tab will be updated as below.
You can observe that there are 2 versions of gson-utils available - 2.0.0 and 2.0.3. However, recollect our discussion on the blog again. Maven uses the 'nearest-wins' startegy. Thus the lower version 2.0.0 is through instead on 2.0.3