转:A Visual Maven Dependency Tree View

原文地址:http://www.summa-tech.com/blog/2011/04/12/a-visual-maven-dependency-tree-view/

The Maven dependency:tree is a helpful plugin that shows where all those jars are coming from in our Maven projects. The default output is text, and sometimes we want something more visual. There are two somewhat easy ways to accomplish this.

1. Using graphml output

Here are the basic steps to get a more visual dependency tree like the one showing below:

Maven Dependency Tree Graph

Since the version 2.1 the Dependency plugin supports different output formats, one of them the GraphML, which is an XML-based file format for graphs.

In you pom.xml you may want to add these lines under the build plugins section to make sure the latest version is used:

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.2</version>
</plugin>
</plugins>
</build>


Use this command to generate the dependency tree, in graphml, saving to a dependency.graphml file:

mvn dependency:tree -DoutputType=graphml -Doutput=dependency.graphml

To visualize GraphML I use yEd Graph Editor which is a cool free visualization tool written in Java.

Now, open yED and select Open Document -> dependency.graphml > OK.
This will open the document, but all you see is some weird lines.

Maven Dependency tree not formatted in yED

Maven Dependency tree not formatted in yED

By default yED will not format the graph, but it has many different formats that you can use. Two simple steps separates you from a nice graph:
1) Select Tools > Fit Note to Label … > OK This should adjust the labels
2) Select Layout > Hierarchical > Orientation > Left to Right > OK

2. Using M2Eclipse plugin

M2Eclipse is a plugin developed by Sonatype. It complements nicely the use of Maven and provides a helpful dependency view.

Once you have the plugin installed (link at the bottom of the page), all you have to do is open the pom.xml and under the tabs select Dependency Hierarchy. On the left side you see the hierarchy with the 2nd, 3rd level jars brought to your project. On the right side is the resolved list. These are the jars that will be actually used in your project.

In case you don’t know, the words between brackets is the Maven dependency scope. Basically test is means it would be only used during test. Provided means that the dependency would be used to compile and execution of tests, but would not be included in the packaged file. Compile is the jars that would end up in you WAR, JAR or other packages as direct dependencies libraries.

m2eclipsescreenshotblog

Here you go, two ways to get a dependency tree that can be easily navigated and understood.

More info:

Maven Dependency Plugin http://maven.apache.org/plugins/maven-dependency-plugin
yED Graph Editor: http://www.yworks.com/en/products_yed_about.html
M2Eclipse Plugin: http://m2eclipse.sonatype.org/
Maven Dependency Scope: http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值