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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4084669/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 11:26:30  来源:igfitidea点击:

How to generate a graph of the dependency between all modules of a Maven project?

javamaven-2

提问by

How to generate a graph of the dependency between all modules of a Maven project (excluding third party libraries like JUnit, SLF4J, etc.)? I couldn't find a way to include all modules into one graph using m2eclipse. Thanks.

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

采纳答案by Pascal Thivent

If the Dependency Graphfeature of m2eclipse doesn't cover your needs, maybe have a look at the Maven Graph Pluginand in particular its graph:reactorgoal.

如果m2eclipse的Dependency Graph功能不能满足您的需求,请查看Maven Graph Plugin,特别是它的graph:reactor目标。

UPDATE: the Dependency Graphfeature was removed in m2eclipse 1.0. For more info see: Maven POM-Editor: Dependency Graph missing

更新在 m2eclipse 1.0删除依赖关系图功能。有关更多信息,请参阅:Maven POM-Editor: Dependency Graph missing

回答by khmarbaise

Haven't you opened the pom via Eclipse and taken a look onto the tab-folders of the pom.xml where one entry is name "Dependency Graph"? Ah sorry...oversight something...You can create a dependency tree via mvn dependency:tree on command line, but this produces no graphical view. An other better solution might be the Maven Overview Plugin

您是否没有通过 Eclipse 打开 pom 并查看 pom.xml 的选项卡文件夹,其中一个条目名为“Dependency Graph”?啊对不起...疏忽了...你可以通过 mvn dependency:tree 在命令行上创建一个依赖树,但这不会产生图形视图。另一个更好的解决方案可能是Maven 概览插件

回答by Raman

Another option is the com.github.janssk1 maven dependency graph plugin. This plugin outputs the dependencies to a graphml file which can be opened and edited in an editor like yEd.

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

To generate the graphml file:

生成graphml文件:

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

This plugin does not currently provide any mechanism to exclude 3rd party dependencies, AFAICT, but they can be deleted manually from the graph using yEd or via an XSLT stylesheet that post-processes the graphml files. Here is a simple stylesheet that will delete the third party dependencies (any dependency not starting with the package provided by the "internal" parameter):

该插件目前不提供任何机制来排除第 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>

And execute it via an XSLT 2.0 compatible processor such as Saxon:

并通过 XSLT 2.0 兼容处理器(例如 Saxon)执行它:

saxon input.graphml exclude-third-party-deps.xsl internal="my.package" > input-internal.graphml

回答by Carlos

Checkout this project too: https://github.com/roclas/pomParser

也可以查看这个项目:https: //github.com/roclas/pomParser

It creates a pretty cool "graph" that can be navigated in both ways (forwards and backwards). The idea is very simple, and you can download and change the code very easily.

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

回答by Yiling

Installed Maven Graph Plugin: http://mvnplugins.fusesource.org/maven/1.10/maven-graph-plugin/index.html, configured it this way to hide third party dependencies. Worked out fine.

安装了 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>

回答by Arnaud Tournier

there exists exactly what you need, it is called Pom Explorer.

确实存在您需要的东西,它被称为Pom Explorer

You can find the website here : github.com/ltearno/pom-explorer

你可以在这里找到这个网站: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 :

它是一个处理 Maven 项目图的工具。作为预告,我可以说在我的机器上它在 4 秒内分析了 4000 个 pom.xml 文件。然后在分析的 pom 图上方提供了许多功能:

  • 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).
  • 依赖分析(谁依赖于 GAV,这个 GAV 依赖于哪个,具有传递性),
  • 分辨率(pom explorer 知道定义的属性在哪里,它管理依赖项和 bom 导入),
  • 操作(您可以使用它来转换您的 pom 图,假设您希望许多项目使用新版本的依赖项),
  • 构建(pom explorer 分析你的 pom 图并知道它们应该被构建的顺序,然后它构建所有东西!它甚至可以观察你的项目目录的变化),
  • 导出(今天有 CSV 和 GRAPHML 导出),
  • 可视化(pom 资源管理器可以向您展示项目图的交互式 3D 可自定义可视化)。

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

谢谢

回答by brostbeef

This might be good enough for some people:

这对某些人来说可能已经足够了:

Command: mvn dependency:tree -Dincludes=com.yourpackage:*

命令:mvn dependency:tree -Dincludes=com.yourpackage:*