主要是参考
http://stackoverflow.com/questions/4084669/how-to-generate-a-graph-of-the-dependency-between-all-modules-of-a-maven-project
中提供的几种工具。
Maven Graph Plugin:
使用该插件首先需要安装
Graphviz,msi安装会将执行文件复制到system32目录下,zip安装则需要将bin路径添加至环境变量。
如何使用:
首先需要在maven的配置信息中添加该插件的库信息,用以下载相关插件:
<project>
<profiles>
<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.4</version>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
然后在pom.xml中添加graph,其实就添加一个graph phase。
<build>
<plugins>
<plugin>
<groupId> org.fusesource.mvnplugins</groupId >
<artifactId> maven-graph-plugin</artifactId>
<configuration>
</configuration>
</plugin>
</plugins>
</build>
configuration参数参考:
link
然后执行
mvn -P graph graph:reactor
然后就会在项目跟路径target目录下生成一张依据pom.xml生成的依赖关系图。
pom文件为:
< project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation ="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
< modelVersion> 4.0.0</ modelVersion >
< groupId> com.company.abc </groupId >
< artifactId> ConcurrencyTester </artifactId >
< version> 0.0.1-SNAPSHOT </version >
< dependencies>
< dependency>
< groupId> org.springframework </groupId >
< artifactId> spring</ artifactId >
< version> 2.5.6</ version >
</ dependency>
< dependency>
< groupId> netease.ddb </groupId >
< artifactId> db </artifactId >
< version> 4.5.1</ version >
< exclusions>
< exclusion>
< groupId> jta </groupId >
< artifactId> jta </artifactId >
</ exclusion>
</ exclusions>
</ dependency>
< dependency>
< groupId> javax.transaction </groupId >
< artifactId> jta </artifactId >
< version> 1.1</ version >
</ dependency>
< dependency>
< groupId> com.google.code.simple-spring-memcached </ groupId>
< artifactId> spymemcached </artifactId >
< version> 2.8.4</ version >
</ dependency>
< dependency>
< groupId> org.apache.ibatis </groupId >
< artifactId> ibatis- sqlmap</ artifactId>
< version> 2.3.4.726 </version >
</ dependency>
</ dependencies>
< build>
< plugins>
< plugin>
< groupId> org.fusesource.mvnplugins </groupId >
< artifactId> maven-graph- plugin</ artifactId>
< configuration>
</ configuration>
</ plugin>
</ plugins>
</ build>
</ project>
方法二:
使用maven-dependencygraph-plugin
mvn com.github.janssk1:maven-dependencygraph-plugin:1.0:graph
会在target目录下生成graphml文件,可以利用yEd Graph Editor工具来查看。
方法三:
爆栈网提供的pomParser这个开源项目有问题,路径、分隔符这些东西都做了硬编码,pom文件也有问题,生成的jar文件没有把配置信息包进去,在生成html的信息的时候会报文件异常。总之是个需要做调整才能使用?的工具,个人未验证。
方法四:
最不济还可以用ant来进行resolve的时候输出依赖信息:
ant -verbose resolve
本文介绍了如何使用Maven的Graph Plugin、maven-dependencygraph-plugin等工具生成Maven项目依赖关系图,包括详细步骤及配置说明。通过这些方法,开发者可以清晰地查看项目的依赖结构。
3915

被折叠的 条评论
为什么被折叠?



