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.