How to generate a graph of the dependency between all modules of a Maven project (excluding third party libraries like JUnit, SLF4J, etc.)? I couldn't find a way to include all modules into one graph using m2eclipse. Thanks.
-
5In IntelliJ, you can get a tree view of dependencies by right clicking your top pom.xml and selecting **Analyze** -> **Analyze Module Dependencies**. Adding as comment because it worked well with no library or configuration needed. – Patrick M Jun 01 '15 at 17:33
-
@PatrickM except it has an [open issue](https://github.com/janssk1/maven-graph-plugin/issues/3) for module support. – OrangeDog Jun 12 '17 at 15:30
8 Answers
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

- 1
- 1

- 562,542
- 136
- 1,062
- 1,124
-
4I like graph:reactor, but I don't see any way to exclude third party dependencies. – Raman Jan 05 '12 at 19:15
-
1Although I like the answer, I don't see a way to exclude 3th party dependencies from the graph like @Raman said. Are we missing something or is it just not possible? – Brambo Jan 18 '12 at 09:16
-
1Also, it is too bad graph:reactor does not have a graphml output mode, similar to `dependency:tree -DoutputType=graphml`. That way the resulting output can be manipulated in an editor like yEd. – Raman Jan 18 '12 at 17:01
-
2For future reference, there is a way to exclude third party dependencies (setting __hideExternal__, this will exclude dependencies not in the reactor build), you just need to be sure to use a recent version of the plugin. e.g. 1.30 available in Maven Central. For further control, specifically excluding or including based on groupId, check [my fork of the plugin](https://github.com/theHilikus/mvnplugins/tree/groupIdFilter) or use v1.31 if my changes are ever accepted in the main repo. there is currently a pending pull request – Hilikus Jul 02 '13 at 18:59
-
1Well, passing -Dhide-external=true from command line does not work wit this plugin (versoin 1.10). Have to add a configuration element in pom.xml to set this variable. – Yiling Aug 16 '13 at 18:27
-
Good plugin but the documentation is not up-to-date, then use the Yiling Liu answer to configure it properly – рüффп Mar 07 '14 at 17:06
-
8The graph plugin is in the central repo now, the linked page is way out of date. So just calling `mvn org.fusesource.mvnplugins:maven-graph-plugin:reactor -Dhide-external=true` does exactly the right thing, without any pom configuration needed. – Stefan Seidel Aug 19 '14 at 07:55
-
-
1I didn't find any documentation, but I found the source code of the Mojo on Github here: https://github.com/fusesource/mvnplugins/blob/master/maven-graph-plugin/src/main/java/org/fusesource/mvnplugins/graph/ProjectMojo.java – OndroMih Nov 13 '16 at 20:53
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

- 17,606
- 5
- 95
- 112
-
1Thanks for providing the XSLT. You can readily extend that to filter on multiple package names, colour code your deps etc, whatever. Very useful when regenerating your graph during the dev cycle. – sbk Jul 31 '13 at 05:45
-
1I tried to used but I get : Failed to execute goal com.github.janssk1:maven-dependencygraph-plugin:1 .2:graph (default-cli) on project cag-parent: Can't write to file:.... – aName Sep 15 '17 at 13:59
-
@aName I have the same issue `Failed to execute goal com.github.janssk1:maven-dependencygraph-plugin:1.0:graph (default-cli) on project email_templates: Can't write to file: /home/acme/acme/module/email_templates/target/email_templates-42.1.0-SNAPSHOT-deps.graphml (No such file or directory)` – Jakub Bochenski Nov 23 '17 at 13:34
there exists exactly what you need, it is called Pom Explorer.
You can find the website here : github.com/ltearno/pom-explorer
It is a tool to work on a graph of maven projects. As a teaser i can say that on my machine it analyzes 4000 pom.xml files in 4 seconds. Then many functionnalities are provided above the analysed pom graph :
- dependency analysis (who depends on GAV, which gavs this GAV depends on, with transitivity),
- resolution (pom explorer knows where are defined properties, it manages dependencies and bom imports),
- manipulation (you can use it to transform you pom graph, let's say if you want many projects to use a new version of a dependency),
- build (pom explorer analyses your pom graph and knows in which order they should be built, then it builds everything ! it can even watch your projects directories for change),
- exporting (today there is CSV and a GRAPHML exports),
- visualization (pom explorer can show you an interactive 3D customizable visualization of your projects graph).
It is in active development right now so don't hesitate to try it, report bugs and ask for useful features ! The documentation is also not complete yet, so again don't hesitate to ask !
Thanks

- 984
- 11
- 11
Just found this one, works great, lots of output formats and ways of filtering: https://github.com/ferstl/depgraph-maven-plugin
Using that, the answer to the question becomes a one-liner (found in this helpful blog entry:
mvn com.github.ferstl:depgraph-maven-plugin:3.0.1:aggregate -DcreateImage=true -DreduceEdges=false -Dscope=compile "-Dincludes=your.group.id*:*"

- 623
- 7
- 16
-
It seems the
options has been removed or changed as if you run the aforementioned command an exception thrown and you should run it without – khesam109 Jun 15 '22 at 05:05option
Checkout this project too: https://github.com/roclas/pomParser
It creates a pretty cool "graph" that can be navigated in both ways (forwards and backwards). The idea is very simple, and you can download and change the code very easily.

- 331
- 2
- 8
-
-
I thought the graph would also be graphical but it seems like the resulting "graph" is pure textural with links to the dependencies. – snap Feb 18 '18 at 17:19
Installed Maven Graph Plugin: http://mvnplugins.fusesource.org/maven/1.10/maven-graph-plugin/index.html, configured it this way to hide third party dependencies. Worked out fine.
<profile>
<id>graph</id>
<pluginRepositories>
<pluginRepository>
<id>mvnplugins.fusesource.org</id>
<url>http://mvnplugins.fusesource.org/repo/release</url>
<releases>
<enabled>true</enabled>
</releases>
</pluginRepository>
</pluginRepositories>
<build>
<plugins>
<plugin>
<groupId>org.fusesource.mvnplugins</groupId>
<artifactId>maven-graph-plugin</artifactId>
<version>1.10</version>
<configuration>
<hideExternal>true</hideExternal>
</configuration>
</plugin>
</plugins>
</build>
</profile>

- 2,817
- 2
- 21
- 27
Haven't you opened the pom via Eclipse and taken a look onto the tab-folders of the pom.xml where one entry is name "Dependency Graph" ? Ah sorry...oversight something...You can create a dependency tree via mvn dependency:tree on command line, but this produces no graphical view. An other better solution might be the Maven Overview Plugin

- 92,914
- 28
- 189
- 235
This might be good enough for some people:
- https://maven.apache.org/plugins/maven-dependency-plugin/examples/filtering-the-dependency-tree.html
Command: mvn dependency:tree -Dincludes=com.yourpackage:*

- 366
- 3
- 15