查看maven项目的依赖关系 mvn dependency:tree
maven-dependency-plugin最大的用途是帮助分析项目依赖,dependency:list能够列出项目最终解析到的依赖列表,dependency:tree能进一步的描绘项目依赖树,dependency:analyze可以告诉你项目依赖潜在的问题,如果你有直接使用到的却未声明的依赖,该目标就会发出警告。maven-dependency-plugin还有很多目标帮助你操作依赖文件,例如dependency:copy-dependencies能将项目依赖从本地Maven仓库复制到某个特定的文件夹下面。比如查看maven项目的依赖,我们可以用下面命令:
mvn dependency:tree
以Dubbo的 dubbo-demo-provider 为例,我们输入这个命令可以获得下面信息:
mvn dependency:tree
Scanning for projects...
Some problems were encountered while building the effective model for com.alibaba:dubbo-demo-provider:jar:2.5.4-SNAPSHOT
'build.plugins.plugin.version' for org.apache.maven.plugins:maven-surefire-plugin is missing. @ com.alibaba:dubbo-parent:2.5.4-SNAPSHOT, /Users/ghj1976/project/github/alibaba/dubbo/pom.xml, line 379, column 12
'build.plugins.plugin.version' for org.apache.maven.plugins:maven-jar-plugin is missing. @ com.alibaba:dubbo-parent:2.5.4-SNAPSHOT, /Users/ghj1976/project/github/alibaba/dubbo/pom.xml, line 365, column 12
'build.plugins.plugin.version' for org.apache.maven.plugins:maven-deploy-plugin is missing. @ com.alibaba:dubbo-parent:2.5.4-SNAPSHOT, /Users/ghj1976/project/github/alibaba/dubbo/pom.xml, line 449, column 12
It is highly recommended to fix these problems because they threaten the stability of your build.
For this reason, future Maven versions might no longer support building such malformed projects.
------------------------------------------------------------------------
Building dubbo-demo-provider 2.5.4-SNAPSHOT
------------------------------------------------------------------------
--- maven-dependency-plugin:2.8:tree (default-cli) @ dubbo-demo-provider ---
com.alibaba:dubbo-demo-provider:jar:2.5.4-SNAPSHOT
+- com.alibaba:dubbo-demo-api:jar:2.5.4-SNAPSHOT:compile
+- com.alibaba:dubbo:jar:2.5.4-SNAPSHOT:compile
|\- commons-logging:commons-logging:jar:1.1.1:compile
+- org.springframework:spring:jar:2.5.6.SEC03:compile
+- org.javassist:javassist:jar:3.15.0-GA:compile
+- org.jboss.netty:netty:jar:3.2.5.Final:compile
+- org.apache.mina:mina-core:jar:1.1.7:compile
+- org.glassfish.grizzly:grizzly-core:jar:2.1.4:compile
|+- org.glassfish.grizzly:grizzly-framework:jar:2.1.4:compile
||\- org.glassfish.gmbal:gmbal-api-only:jar:3.0.0-b023:compile
|| \- org.glassfish.external:management-api:jar:3.0.0-b012:compile
|+- org.glassfish.grizzly:grizzly-portunif:jar:2.1.4:compile
|\- org.glassfish.grizzly:grizzly-rcm:jar:2.1.4:compile
+- org.apache.httpcomponents:httpclient:jar:4.1.2:compile
|+- org.apache.httpcomponents:httpcore:jar:4.1.2:compile
|\- commons-codec:commons-codec:jar:1.4:compile
+- com.alibaba:fastjson:jar:1.1.39:compile
+- com.thoughtworks.xstream:xstream:jar:1.4.1:compile
|+- xmlpull:xmlpull:jar:1.1.3.1:compile
|\- xpp3:xpp3_min:jar:1.1.4c:compile
+- org.apache.bsf:bsf-api:jar:3.1:compile
+- org.apache.zookeeper:zookeeper:jar:3.3.3:compile
|\- jline:jline:jar:0.9.94:compile
+- com.github.sgroschupf:zkclient:jar:0.1:compile
+- com.netflix.curator:curator-framework:jar:1.1.16:compile
|+- com.netflix.curator:curator-client:jar:1.1.16:compile
|\- com.google.guava:guava:jar:11.0.1:compile
| \- com.google.code.findbugs:jsr305:jar:1.3.9:compile
+- com.googlecode.xmemcached:xmemcached:jar:1.3.6:compile
+- org.apache.cxf:cxf-rt-frontend-simple:jar:2.6.1:compile
|+- org.apache.cxf:cxf-api:jar:2.6.1:compile
||+- org.codehaus.woodstox:woodstox-core-asl:jar:4.1.2:runtime
|||\- org.codehaus.woodstox:stax2-api:jar:3.1.1:runtime
||+- org.apache.ws.xmlschema:xmlschema-core:jar:2.0.2:compile
||+- org.apache.geronimo.specs:geronimo-javamail_1.4_spec:jar:1.7.1:compile
||\- wsdl4j:wsdl4j:jar:1.6.2:compile
|+- org.apache.cxf:cxf-rt-core:jar:2.6.1:compile
||\- com.sun.xml.bind:jaxb-impl:jar:2.1.13:compile
|\- org.apache.cxf:cxf-rt-bindings-soap:jar:2.6.1:compile
| \- org.apache.cxf:cxf-rt-databinding-jaxb:jar:2.6.1:compile
+- org.apache.cxf:cxf-rt-transports-http:jar:2.6.1:compile
+- org.apache.thrift:libthrift:jar:0.8.0:compile
|\- commons-lang:commons-lang:jar:2.5:compile
+- com.caucho:hessian:jar:4.0.7:compile
+- javax.servlet:servlet-api:jar:2.5:compile
+- org.mortbay.jetty:jetty:jar:6.1.26:compile
|+- org.mortbay.jetty:jetty-util:jar:6.1.26:compile
|\- org.mortbay.jetty:servlet-api:jar:2.5-20081211:compile
+- log4j:log4j:jar:1.2.16:compile
+- org.slf4j:slf4j-api:jar:1.6.2:compile
+- redis.clients:jedis:jar:2.1.0:compile
|\- commons-pool:commons-pool:jar:1.5.5:compile
+- javax.validation:validation-api:jar:1.0.0.GA:compile
+- org.hibernate:hibernate-validator:jar:4.2.0.Final:compile
+- javax.cache:cache-api:jar:0.4:compile
+- junit:junit:jar:4.10:test
|\- org.hamcrest:hamcrest-core:jar:1.1:test
+- org.easymock:easymock:jar:3.0:test
|+- cglib:cglib-nodep:jar:2.2:test
|\- org.objenesis:objenesis:jar:1.2:test
+- org.easymock:easymockclassextension:jar:3.0:test
\- com.googlecode.jmockit:jmockit:jar:0.999.8:test
------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Total time: 2.057 s
Finished at: 2016-03-29T15:41:31+08:00
Final Memory: 12M/309M
------------------------------------------------------------------------
unpack和copy类似,只不过它会把拷来的包解开,例如:
<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>${project.parent.version}</version>
<outputDirectory>${project.build.directory}/dubbo</outputDirectory>
<includes>META-INF/assembly/**</includes>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
…
dependency:unpack 中常用参数有:
[*] artifactItems:用来包含声明需要解压的文件元素;
[*] artifactItem:声明需要解压的文件;
[*] outputDirectory:定义解压后输出的文件夹;
[*] includes:定义输出包含的规则;
[*] excludes:定义输出排除的规则。
Apache Maven Dependency Plugin中比较常用的功能有:
[*] dependency:copy用来拷贝某一个或多个特定文件到指定目录;
[*] dependency:copy-dependencies用来拷贝依赖的文件到指定目录;
[*] dependency:unpack与 copy 类似,但会解压文件;
[*] dependency:unpack-dependencies 与 copy-dependencies 类似,但会解压文件;
参考资料:
使用maven命令来分析jar包之间的依赖关系
http://outofmemory.cn/code-snippet/10914/maven-command-dependency
页:
[1]