Skip to content

balajeetm/maven-safe-haven

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 

maven-safe-haven

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

projectStructure

Its a multi module maven project, consisting of

Now, if you recollect our discussion on my blog, we were discussing conflict resolution and picked a scenario as below

Conflict-Resolution

The library names used their was generic. Considering the current project structure, the updated scenario would like below with explicit library names and versions

ConflictResolution

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?

Guide to verify conflict resolution

  • 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

Dependency Hierarchy Button

  • 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

lib-b

  • 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

gson-utils

  • Step6 Now filter for guava. The dependency tab will be updated as below.
    You can observe that there are 2 versions of guava as well. But this time both versions are equidistant. Thus maven uses the "highest-version-wins" startegy and thus guava 19.0 is through

guava

That's all folks! Have fun unjargoning !!!
Unjargon

Releases

No releases published

Packages

No packages published