Customized Maven Dependency Diagrams

I wanted to have a diagram of Maven dependencies but just the ones with a certain groupId should be included. I do not know whether the m2e Eclipse plugin provided such a feature but with release 1.0 the dependency diagram feature was removed. IntelliJ IDEA Ultimate has a nice dependency diagram but you cannot filter for certain dependencies just for scope.

O.k. Back to the roots. My idea was

  • to use the tree goal of the Maven dependency plugin
  • and then filter just the dependencies I am interested in with grep
  • and then convert it somehow to a format yEd can read
  • Finally use yEd auto layout to make a nice diagram

Thanks to the Maven dependency plugin this was much easier because

For demonstration I use the Cocoon 3 trunk. To generate a .graphml-file with all dependencies:

mvn org.apache.maven.plugins:maven-dependency-plugin:2.4:tree -DoutputFile=/tmp/cocoon-all.graphml -DoutputType=graphml -Dverbose=true

To include just the dependencies with groupId org.apache.cocoon.*:

mvn org.apache.maven.plugins:maven-dependency-plugin:2.4:tree -Dinclues=org.apache.cocoon.* -DoutputFile=/tmp/cocoon-all_only-org.apache.cocoon.graphml -DoutputType=graphml -Dverbose=true

In yEd you can simply

  • select all nodes
  • change the width of all nodes at once
  • and then use the tree automatic layout

to get a nice looking diagram.

If you don’t want to see the scope compile at the edges you can simply process the .graphml-file with sed:

sed ‘s/compile<\/y:EdgeLabel>/<\/y:EdgeLabel>/g’ /tmp/cocoon-all_only-org.apache.cocoon.graphml >/tmp/cocoon-all_only-org.apache.cocoon_no-compile-edge-labels.graphml

Great! I generated the customized dependency diagram I needed with freely available tools! Thanks to Maven dependency plugin and yEd!

For you to look at the final dependency diagram without edge labels for dependencies with groupId org.apache.cocoon.*:

Initial diagram with all dependencies of Cocoon 3:

Thanks for reading. Feedback welcome on your experience with Maven dependency diagrams.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s