59

Is there a way to have a Maven dependency graph of a given set of projects (if possible, graphical), without having 3rd party dependencies drawn too? Or where I opt out the dependencies I'm not interested in?

I'd like to point the tool/plugin at a number of POM files and see a description of the dependencies between those projects.

Duncan Jones
  • 67,400
  • 29
  • 193
  • 254
Simhor
  • 701
  • 1
  • 6
  • 8

5 Answers5

52

If you use mvn dependency:tree, you can specify files to exclude or include with -Dexcludes and -Dincludes. The output is an ASCII-art style depiction of the dependencies.

See the docs for more info.

Duncan Jones
  • 67,400
  • 29
  • 193
  • 254
  • 2
    But this is just for a given project, is it not ? I'd really like to see the relationship between my projects. – Simhor Jul 01 '13 at 20:36
  • 3
    Something like this (http://mvnplugins.fusesource.org/maven/1.0/maven-graph-plugin/), but apparently this one doesn't offer to opt out the 3rd parties – Simhor Jul 01 '13 at 20:38
  • 1
    @Simhor So you want to point at a number of POM files and see a graph of the relationships between those projects? – Duncan Jones Jul 01 '13 at 20:38
  • Alternatively the program could just infer the submodules, just by giving the top pom.xml – Simhor Jul 01 '13 at 20:41
33

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

Arnaud Tournier
  • 984
  • 11
  • 11
  • Nice tool, can you explain what needs to be done to simply get a graph of dependencies for a given set of maven projects? So far I can analyze the folder containing the set of projects and list all gav with pom-explorer. What do I need to do to get a graph of dependencies between those projects (without 3rd parties) for further processing. What I want is to just have a simple graphs between the maven projects to know how to build the project in the right order. – Moonlit Jul 09 '17 at 06:30
  • You can use the `graph export [gav_filter]` command to export a graphml file representing your projects. And then you can filter it with yEd for example. If you like the 3d WebGL graph command (graph), you can then filter teh displayed GAVs directly in the graphical interface. Maybe best to post this question as a documentation issue on the github project, so that other people can benefit...https://github.com/ltearno/pom-explorer/issues – Arnaud Tournier Aug 02 '17 at 13:16
  • Sorry, but the gui is cumbersome. Is there a command line way to use the tool? – RoyM Oct 19 '17 at 14:52
  • The gui tries to be command line like. For the moment there is no other choice. Expect maybe to write a little command line wrapper around the pom-explorer.jar – Arnaud Tournier Oct 24 '17 at 13:42
12
mvn com.github.ferstl:depgraph-maven-plugin:aggregate -Dincludes=com.yourcompany.pkg

Does well for me.

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
paul_h
  • 1,859
  • 3
  • 19
  • 27
  • 1
    The best I tried so far, but it gets fooled by compile/test dependencies. A dependency with 'test' scope by default, overriden as 'compile' is a subproject is not taken in account. Some dependencies may appear several times. – Laurent Caillette Dec 19 '18 at 08:31
4

I like depgraph-maven-plugin to visualize dependencies in a multi-module project, see also previous answer.

To get an aggregated result in text format (like dependency:tree) for your modules, use:

mvn com.github.ferstl:depgraph-maven-plugin:aggregate -DgraphFormat=text -Dincludes=myGroupId

The syntax for includes is the same as with maven-dependency-plugin includes.

It has a lot of properties to customize the result/behavior. I prefer to use it together with graphviz, so I can use the (default) graph format dot and let it create a png file in the target folder:

mvn com.github.ferstl:depgraph-maven-plugin:aggregate -DcreateImage -Dincludes=myGroupId

There are also other interesting goals, e.g. an example goal to quickly play around with the properties.

msa
  • 702
  • 7
  • 14
2

You can use POM2RDF to generate an RDF graph of your project dependencies (and their dependencies, and so on) that you can then query to get a Software Bill of Materials or visualize as a dependency graph.

Disclaimer: I'm the author.