ferstl / depgraph-maven-plugin

A Maven plugin that generates dependency graphs in various formats (DOT, GML, PlantUML, JSON and Text)
Apache License 2.0
554 stars 84 forks source link

feat(mermaid): add a new output format #151

Open phiz71 opened 2 years ago

phiz71 commented 2 years ago

Add the possibility to use mermaid syntax. See https://mermaid-js.github.io/mermaid/#/flowchart?id=flowcharts-basic-syntax

150

ferstl commented 2 years ago

Thanks a lot for this PR. I‘ll review it soon. Please be patient.

christopwner commented 2 months ago

this would be a great addition since mermaid can be embedded in github and gitlab. i installed this locally to test it out, and here's the output with following cmd:

christopwner@desktop:~/projects/depgraph-maven-plugin/src/test/projects/depgraph-maven-plugin-test/sub-parent/module-3$ mvn com.github.ferstl:depgraph-maven-plugin:4.0.2-SNAPSHOT:graph -DgraphFormat=mermaid

actual:

flowchart TD
  %% Node Definitions:
  com.github.ferstl:module-1:jar["module-1"]
  com.github.ferstl:module-2:zip["module-2"]
  com.github.ferstl:module-3:jar["module-3"]
  junit:junit:jar["junit<br/><font size=1>(test)</font>"]
  org.hamcrest:hamcrest-core:jar["hamcrest-core<br/><font size=1>(test)</font>"]
  com.github.ferstl:module-2:jar["module-2"]
  com.mysema.querydsl:querydsl-core:jar["querydsl-core"]
  com.google.guava:guava:jar["guava"]
  com.google.code.findbugs:jsr305:jar["jsr305"]
  com.mysema.commons:mysema-commons-lang:jar["mysema-commons-lang"]
  com.infradna.tool:bridge-method-annotation:jar["bridge-method-annotation"]

  %% Edge Definitions:
  com.github.ferstl:module-1:jar --> com.github.ferstl:module-2:zip
  com.github.ferstl:module-3:jar --> com.github.ferstl:module-1:jar
  junit:junit:jar --> org.hamcrest:hamcrest-core:jar
  com.github.ferstl:module-2:jar --> junit:junit:jar
  com.github.ferstl:module-3:jar --> com.github.ferstl:module-2:jar
  com.mysema.querydsl:querydsl-core:jar --> com.google.guava:guava:jar
  com.mysema.querydsl:querydsl-core:jar --> com.google.code.findbugs:jsr305:jar
  com.mysema.querydsl:querydsl-core:jar --> com.mysema.commons:mysema-commons-lang:jar
  com.mysema.querydsl:querydsl-core:jar --> com.infradna.tool:bridge-method-annotation:jar
  com.github.ferstl:module-3:jar --> com.mysema.querydsl:querydsl-core:jar

i see a few issues with graph based on the expectations file you added, src/test/projects/depgraph-maven-plugin-test/expectations/graph_module-3.mmd, see following:

expected:

flowchart TD
  %% Node Definitions:
  com.github.ferstl:module-1:jar["module-1"]
  commons-codec:commons-codec:jar["commons-codec"]
  org.apache.commons:commons-lang3:jar["commons-lang3"]
  com.github.ferstl:module-3:jar["module-3"]
  com.github.ferstl:module-2:jar["module-2"]
  com.google.guava:guava:jar["guava"]
  com.mysema.querydsl:querydsl-core:jar["querydsl-core"]
  com.google.code.findbugs:jsr305:jar["jsr305"]
  com.mysema.commons:mysema-commons-lang:jar["mysema-commons-lang"]
  com.infradna.tool:bridge-method-annotation:jar["bridge-method-annotation"]

  %% Edge Definitions:
  com.github.ferstl:module-1:jar --> commons-codec:commons-codec:jar
  com.github.ferstl:module-1:jar --> org.apache.commons:commons-lang3:jar
  com.github.ferstl:module-3:jar --> com.github.ferstl:module-1:jar
  com.github.ferstl:module-2:jar --> com.google.guava:guava:jar
  com.github.ferstl:module-3:jar --> com.github.ferstl:module-2:jar
  com.mysema.querydsl:querydsl-core:jar --> com.google.code.findbugs:jsr305:jar
  com.mysema.querydsl:querydsl-core:jar --> com.mysema.commons:mysema-commons-lang:jar
  com.mysema.querydsl:querydsl-core:jar --> com.infradna.tool:bridge-method-annotation:jar
  com.github.ferstl:module-3:jar --> com.mysema.querydsl:querydsl-core:jar

aside from the missing nodes like commons-codec and incorrect edges, i also found looking that two module-2 nodes are defined, one as jar and other zip in actual mmd output. i cleaned and reran to confirm issue was there (and not present in dot output). see following snippet from first graph:

  com.github.ferstl:module-2:zip["module-2"]
  com.github.ferstl:module-3:jar["module-3"]
  junit:junit:jar["junit<br/><font size=1>(test)</font>"]
  org.hamcrest:hamcrest-core:jar["hamcrest-core<br/><font size=1>(test)</font>"]
  com.github.ferstl:module-2:jar["module-2"]