How to generate a graph of the dependency between all modules of a Maven project?

Another option is the com.github.janssk1 maven dependency graph plugin. This plugin outputs the dependencies to a graphml file which can be opened and edited in an editor like yEd.

To generate the graphml file:

mvn com.github.janssk1:maven-dependencygraph-plugin:1.0:graph

This plugin does not currently provide any mechanism to exclude 3rd party dependencies, AFAICT, but they can be deleted manually from the graph using yEd or via an XSLT stylesheet that post-processes the graphml files. Here is a simple stylesheet that will delete the third party dependencies (any dependency not starting with the package provided by the "internal" parameter):

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:gml="http://graphml.graphdrawing.org/xmlns/graphml"
    version="2.0">

  <xsl:output method="xml"/>
  <xsl:param name="internal"/>

  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="gml:node[not(starts-with(@id, $internal))]"/>

  <xsl:template match="gml:edge[not(starts-with(@source, $internal)) or not(starts-with(@target, $internal))]"/>

</xsl:stylesheet>

And execute it via an XSLT 2.0 compatible processor such as Saxon:

saxon input.graphml exclude-third-party-deps.xsl internal="my.package" > input-internal.graphml

If the Dependency Graph feature of m2eclipse doesn't cover your needs, maybe have a look at the Maven Graph Plugin and in particular its graph:reactor goal.

UPDATE: the Dependency Graph feature was removed in m2eclipse 1.0. For more info see: Maven POM-Editor: Dependency Graph missing

Tags:

Java

Maven 2