[英]How to generate a graph of the dependency between all modules of a Maven project?
如何生成Maven項目所有模塊之間的依賴關系圖(不包括JUnit、SLF4J等第三方庫)? 我找不到使用 m2eclipse 將所有模塊包含在一個圖中的方法。 謝謝。
如果 m2eclipse 的Dependency Graph功能不能滿足您的需求,請查看Maven Graph Plugin ,特別是它的graph:reactor
目標。
更新:在 m2eclipse 1.0中刪除了依賴關系圖功能。 有關更多信息,請參閱: Maven POM-Editor: Dependency Graph missing
另一種選擇是 com.github.janssk1 maven 依賴關系圖插件。 該插件將依賴項輸出到一個 graphml 文件,該文件可以在 yEd 等編輯器中打開和編輯。
生成graphml文件:
mvn com.github.janssk1:maven-dependencygraph-plugin:1.0:graph
該插件目前不提供任何機制來排除第 3 方依賴項 AFAICT,但可以使用 yEd 或通過對 graphml 文件進行后處理的 XSLT 樣式表從圖中手動刪除它們。 這是一個簡單的樣式表,它將刪除第三方依賴項(任何不以“internal”參數提供的包開頭的依賴項):
<?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>
並通過 XSLT 2.0 兼容處理器(例如 Saxon)執行它:
saxon input.graphml exclude-third-party-deps.xsl internal="my.package" > input-internal.graphml
確實存在您需要的東西,它被稱為Pom Explorer 。
你可以在這里找到這個網站: github.com/ltearno/pom-explorer
它是一個處理 Maven 項目圖的工具。 作為預告,我可以說在我的機器上它在 4 秒內分析了 4000 個 pom.xml 文件。 然后在分析的 pom 圖上方提供了許多功能:
它現在正在積極開發中,所以不要猶豫嘗試它,報告錯誤並尋求有用的功能! 文檔還沒有完成,所以再次不要猶豫,問!
謝謝
也可以查看這個項目: https : //github.com/roclas/pomParser
它創建了一個非常酷的“圖形”,可以以兩種方式(向前和向后)導航。 這個想法很簡單,你可以很容易地下載和更改代碼。
安裝了 Maven Graph Plugin: http : //mvnplugins.fusesource.org/maven/1.10/maven-graph-plugin/index.html ,以這種方式配置它以隱藏第三方依賴項。 工作得很好。
<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>
剛找到這個,效果很好,有很多輸出格式和過濾方式: https : //github.com/ferstl/depgraph-maven-plugin
使用它,問題的答案變成了一個單行(在這個有用的博客條目中找到:
mvn com.github.ferstl:depgraph-maven-plugin:3.0.1:aggregate -DcreateImage=true -DreduceEdges=false -Dscope=compile "-Dincludes=your.group.id*:*"
您是否沒有通過 Eclipse 打開 pom 並查看 pom.xml 的選項卡文件夾,其中一個條目名為“Dependency Graph” ? 啊對不起...疏忽了...你可以通過 mvn dependency:tree 在命令行上創建一個依賴樹,但這不會產生圖形視圖。 另一個更好的解決方案可能是Maven 概覽插件
這對某些人來說可能已經足夠了:
命令:mvn dependency:tree -Dincludes=com.yourpackage:*
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.