Maven: Discovering Dependency Conflicts

Among other things, Maven’s dependency plugin displays the result of Maven’s dependency resolution mechanism. The output of the dependency:tree goal makes it easy to see where transitive dependencies come from. This week I discovered that recent versions of the plugin also support a verbose flag that lists conflicts and shows how Maven resolved them.

Change to your project’s base directory and run the following command:

$ mvn dependency:tree -Dverbose

The dependencies displayed in parenthesis have been omitted due to being in conflict with higher priority artifacts.

Here’s a bit of command line magic that highlights the conflicts in red when using GNU grep (without dropping the non-matching lines!):

mvn dependency:tree -Dverbose | grep '(.* conflict\|^'

If you want to display colors in less, use the following command:

mvn dependency:tree -Dverbose | grep --color=always '(.* conflict\|^' | less -r

When adding a new dependency to a project it’s a good idea to re-run this command to see whether it causes conflicts to prevent weird bugs that may be difficult to debug.

This entry was posted in java and tagged , , . Bookmark the permalink.

3 Responses to Maven: Discovering Dependency Conflicts

  1. Chris Micallef says:

    IntelliJ also has a very nice way of displaying the mavem dependency tree … might come very handy at times :)

  2. Nicolas Ford says:

    This is a great posst thanks

Leave a Reply to Nicolas Ford Cancel reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s