A Visual Maven Dependency Tree View

April 12th, 2011 Handerson Gomes, Consultant  (email the author)

The Maven dependency:tree is a helpful plugin that shows where all those jars are coming from in our Maven projects. The default output is text, and sometimes we want something more visual. There are two somewhat easy ways to accomplish this.

1. Using graphml output

Here are the basic steps to get a more visual dependency tree like the one showing below:

Maven Dependency Tree Graph

Since the version 2.1 the Dependency plugin supports different output formats, one of them the GraphML, which is an XML-based file format for graphs.

In you pom.xml you may want to add these lines under the build plugins section to make sure the latest version is used:

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.2</version>
</plugin>
</plugins>
</build>


Use this command to generate the dependency tree, in graphml, saving to a dependency.graphml file:

mvn dependency:tree -DoutputType=graphml -DoutputFile=dependency.graphml

To visualize GraphML I use yEd Graph Editor which is a cool free visualization tool written in Java.

Now, open yED and select Open Document -> dependency.graphml > OK.
This will open the document, but all you see is some weird lines.

Maven Dependency tree not formatted in yED

Maven Dependency tree not formatted in yED

By default yED will not format the graph, but it has many different formats that you can use. Two simple steps separates you from a nice graph:
1) Select Tools > Fit Note to Label … > OK This should adjust the labels
2) Select Layout > Hierarchical > Orientation > Left to Right > OK

2. Using M2Eclipse plugin

M2Eclipse is a plugin developed by Sonatype. It complements nicely the use of Maven and provides a helpful dependency view.

Once you have the plugin installed (link at the bottom of the page), all you have to do is open the pom.xml and under the tabs select Dependency Hierarchy. On the left side you see the hierarchy with the 2nd, 3rd level jars brought to your project. On the right side is the resolved list. These are the jars that will be actually used in your project.

In case you don’t know, the words between brackets is the Maven dependency scope. Basically test is means it would be only used during test. Provided means that the dependency would be used to compile and execution of tests, but would not be included in the packaged file. Compile is the jars that would end up in you WAR, JAR or other packages as direct dependencies libraries.

m2eclipsescreenshotblog

Here you go, two ways to get a dependency tree that can be easily navigated and understood.

More info:

Maven Dependency Plugin http://maven.apache.org/plugins/maven-dependency-plugin
yED Graph Editor: http://www.yworks.com/en/products_yed_about.html
M2Eclipse Plugin: http://m2eclipse.sonatype.org/
Maven Dependency Scope: http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope

Entry Filed under: Agile and Development

7 Comments Add your own

  • 1. Artur Biesiadowski  |  April 13th, 2011 at 5:17 am

    If you enable advanced options in m2eclipse (inside preferences), you will get ‘Dependency Graph’ tab in addition to ‘Dependency Hierarchy’. It will show you quite nice graphical representation of dependencies, with conflicts marked in red, possibility to highlight dependencies for given node etc.

    You can check simple example at
    https://docs.sonatype.org/download/attachments/1999028/pom-editor-dependency-graph.png

  • 2. Mirko Friedenhagen  |  April 15th, 2011 at 2:51 pm

    As far as I know, dependency resolution with the dependency plugin may result in different results than the built-in resolution, so m2eclipse should be more accurate.

  • 3. Technical Related Notes &&hellip  |  April 18th, 2011 at 4:59 am

    [...] A Visual Maven Dependency Tree View | Summa Blog (tags: maven java) [...]

  • 4. Visualize Maven Project D&hellip  |  January 13th, 2012 at 8:07 am

    [...] could also generate the output f.ex. in the graphml format & visualize it in Eclipse. Advertisement LD_AddCustomAttr(“AdOpt”, “1″); LD_AddCustomAttr(“Origin”, “other”); [...]

  • 5. Michael  |  February 14th, 2012 at 11:03 am

    As described here: http://maven.apache.org/plugins/maven-dependency-plugin/tree-mojo.html Parameter “output” is deprecated. You should use “outputFile” instead.

    So the command:
    mvn dependency:tree -DoutputType=graphml -Doutput=dependency.graphml

    must be changed to:

    mvn dependency:tree -DoutputType=graphml -DoutputFile=dependency.graphml

  • 6. Handerson Gomes  |  February 14th, 2012 at 2:11 pm

    Thank you Michael, I updated the article to use -DoutputFile.

  • 7. Maven dependency | Trd4ru&hellip  |  April 21st, 2012 at 3:43 am

    [...] A Visual Maven Dependency Tree View | Summa BlogApr 12, 2011 … The Maven dependency:tree is a helpful plugin that shows where all those jars are coming from in our Maven projects. The default output is text … [...]

Leave a Comment

Required

Required, hidden


two + 4 =

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed

© 2010-2012 Summa All Rights Reserved -- Copyright notice by Blog Copyright