如何生成一个Maven项目的所有模块之间的依赖关系图?

如何生成Maven项目的所有模块(不包括像JUnit,SLF4J等第三方库)之间的依赖关系图? 我找不到使用m2eclipse将所有模块包含到一个图中的方法。 谢谢。

如果m2eclipse的依赖图function不能满足你的需求,那么可以看看Maven Graph Plugin ,特别是它的graph:reactor目标。

更新在m2eclipse 1.0删除依赖关系图function。 有关更多信息,请参阅: Maven POM编辑器:依赖关系图缺失

另一种select是com.github.janssk1 maven依赖图插件 。 这个插件将依赖关系输出到一个graphml文件,该文件可以在像yEd这样的编辑器中打开和编辑。

要生成graphml文件:

 mvn com.github.janssk1:maven-dependencygraph-plugin:1.0:graph 

这个插件目前不提供任何机制来排除第三方依赖关系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

你可以在这里find网站: github.com/ltearno/pom-explorer

这是一个在Maven项目图上工作的工具。 作为一个传情我可以说,在我的机器上,它分析4000 pom.xml文件在4秒钟。 然后在分析的pom图上面提供了许多函数:

  • 依赖性分析(依赖于GAV,GAV这个GAV依赖于,具有传递性),
  • 分辨率(pom的资源pipe理器知道在哪里定义的属性,它pipe理依赖和bom导入),
  • 操纵(你可以用它来改变你的graphics,假设你想让很多项目使用新版本的依赖项),
  • 编译器(pom explorer)分析你的pom图,知道它应该以什么样的顺序构build,然后构build一切,它甚至可以监视你的项目目录的变化),
  • 导出(今天有CSV和GRAPHML出口),
  • 可视化(POM资源pipe理器可以显示您的项目graphics交互式3D可定制的可视化)。

现在正在积极发展,所以不要犹豫,试试吧,报告错误,寻求有用的function! 文档还不完整,所以再次不要犹豫,问!

谢谢

也检出这个项目: https : //github.com/roclas/pomParser

它创build了一个非常酷的“graphics”,可以在两种方式(向前和向后)导航。 这个想法很简单,你可以很容易地下载和更改代码。

安装的Maven图表插件: http : //mvnplugins.fusesource.org/maven/1.10/maven-graph-plugin/index.html ,这样configuration就隐藏了第三方的依赖关系。 工作得很好。

  <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> 

你是不是通过Eclipse打开了pom文件,并查看了pom.xml的标签文件夹,其中一个条目名为“Dependency Graph” ? 对不起…忽略了一些东西…你可以通过命令行上的mvn dependency:tree来创build依赖关系树,但是这不会产生graphics视图。 另一个更好的解决scheme可能是Maven概述插件