3

My project is composed of several modules, which depend on each other and it is not that simple to keep in mind what depends on what, therefore I wanted to have the dependency graph visualized.

I am aware of the possibility to create a textual description in dot format of the dependencies:

mvn dependency:tree -Dincludes=ch.sahits.game -DappendOutput=true
                    -DoutputType=dot -DappendOutput=true
                    -DoutputFile=output.dot

This will generate output.dot files in each module. As there is basically one module that collects all others, I only want to look at that one and it looks like this:

digraph "ch.sahits.game:OpenPatricianDisplay:jar:0.8.0-SNAPSHOT" { 
    "ch.sahits.game:OpenPatricianDisplay:jar:0.8.0-SNAPSHOT" -> "ch.sahits.game:OpenPatricianImage:jar:0.8.0-SNAPSHOT:compile" ; 
    "ch.sahits.game:OpenPatricianDisplay:jar:0.8.0-SNAPSHOT" -> "ch.sahits.game:OpenPatricianData:jar:0.8.0-SNAPSHOT:compile" ; 
    "ch.sahits.game:OpenPatricianDisplay:jar:0.8.0-SNAPSHOT" -> "ch.sahits.game:OpenPatricianSound:jar:0.8.0-SNAPSHOT:compile" ; 
    "ch.sahits.game:OpenPatricianDisplay:jar:0.8.0-SNAPSHOT" -> "ch.sahits.game:OpenPatricianJavaFX:jar:0.8.0-SNAPSHOT:compile" ; 
    "ch.sahits.game:OpenPatricianDisplay:jar:0.8.0-SNAPSHOT" -> "ch.sahits.game:MarvinFXEssentials:jar:0.8.0-SNAPSHOT:test" ; 
    "ch.sahits.game:OpenPatricianDisplay:jar:0.8.0-SNAPSHOT" -> "ch.sahits.game:OpenPatricianServer:jar:0.8.0-SNAPSHOT:compile" ; 
    "ch.sahits.game:OpenPatricianImage:jar:0.8.0-SNAPSHOT:compile" -> "ch.sahits.game:OpenPatricianModel:jar:0.8.0-SNAPSHOT:compile" ; 
    "ch.sahits.game:OpenPatricianModel:jar:0.8.0-SNAPSHOT:compile" -> "ch.sahits.game:GameEvent:jar:0.8.0-SNAPSHOT:compile" ; 
    "ch.sahits.game:OpenPatricianSound:jar:0.8.0-SNAPSHOT:compile" -> "ch.sahits.game:OpenPatricianUtilities:jar:0.8.0-SNAPSHOT:compile" ; 
    "ch.sahits.game:OpenPatricianJavaFX:jar:0.8.0-SNAPSHOT:compile" -> "ch.sahits.game:OpenPatricianGameEvent:jar:0.8.0-SNAPSHOT:compile" ; 
    "ch.sahits.game:OpenPatricianGameEvent:jar:0.8.0-SNAPSHOT:compile" -> "ch.sahits.game:OpenPatricianClientServerInterface:jar:0.8.0-SNAPSHOT:compile" ; 
    "ch.sahits.game:OpenPatricianServer:jar:0.8.0-SNAPSHOT:compile" -> "ch.sahits.game:OpenPatricianEngine:jar:0.8.0-SNAPSHOT:compile" ; 
 }

For my purposes however it is incomplete, as it for example ignores dependencies of the OpenPatricianJavaFX on OpenPatricianImage. To remedy that I went around and collected all the missing information, so that I then could generate the graph image with graphviz:

dot -Tpng output.dot -o dependencies.png

The result is a mess, while it is correct representation it is no help in documenting the dependencies. enter image description here There are some posts addressing the same issue, but they are all a bit dated:

  1. How to generate a graph of the dependency between all modules of a Maven project? provides as solution based on Eclipse and it seems that particular plugin no longer exists.
  2. Maven dependency graph basically describes the same approach I have chosen. This post does as well with a bit more details.
  3. A Visual Maven Dependency Tree View is probably the plugin mentioned in the first point.
  4. Maven Dependencies Diagram looks like the perfect solution for IntelliJ, but I cannot find that plug-in anywhere.

So my question boils down to advice on the two steps:

  1. Generate a model of the dependencies within my project while ignoring third party dependencies: Is there another/better way than the maven-dependency-plugin?
  2. How to generate a readable diagram from the output of step 1)? Possible option would also include some way manually adjust the layout before it is exported to an image.
Community
  • 1
  • 1
hotzst
  • 7,238
  • 9
  • 41
  • 64
  • 1
    You know there's a [built in dependency graph](https://www.jetbrains.com/help/idea/2016.3/working-with-maven-dependencies.html)? –  Dec 25 '16 at 08:50
  • 1
    @RC. No, I was not aware of that, this seems in fact to be the solution described [here](Maven Dependencies Diagram). The issue there is that it includes all dependencies also those from outside the project. – hotzst Dec 25 '16 at 09:05
  • What you can do, is use a filter on the view, that should do it, if not (**but don't save anything**), you can exclude the deps you don't want (right click => exclude) to get the graph you want (NB: this will change your pom.xml so don't save it) –  Dec 25 '16 at 09:51
  • 1
    On any non-trivial project such a graph has no use -- it's impossible to view enough information at a zoom level where you can read the text and its not usually searchable. Pipe the output of the dependency tree to a file and you can search it for the specific thing you're interested in. On a trivial project you don't need such a thing either. – Software Engineer Dec 26 '16 at 00:48
  • Ah so close! What is missing in the dependency view is a better filter IMO. For example, a RegEx on the project name. All our projects have a distinct prefix so this would suffice for me. – mihca Jun 17 '21 at 07:50

0 Answers0