Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

maven-2

People also ask

What is module dependency graph?

1. Graph representing the system modules as nodes and the module-level relationships as edges between these nodes. Learn more in: Software Module Clustering Using Bio-Inspired Algorithms. Find more terms and definitions using our Dictionary Search.

Which Maven command is to list all dependencies of a project hierarchically?

In Maven, you can use mvn dependency:tree to display the project dependencies in tree format.

Can two Maven modules depend on each other?

Because modules within a multi-module build can depend on each other, it is important that the reactor sorts all the projects in a way that guarantees any project is built before it is required. The following relationships are honoured when sorting projects: a project dependency on another module in the build.

Where can I find dependencies in Maven?

In your project's POM, press Ctrl and hover the mouse over the dependency. Click the dependency to open the dependency's POM. In the dependency POM, view the active dependency, its transitive dependencies and their versions. You can check the origin from which the dependency was pulled in.


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


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

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


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.