查看maven項目的依賴關係 mvn dependency:tree

maven-dependency-plugin最大的用途是幫助分析項目依賴,dependency:list可以列出項目最終解析到的依賴列表,dependency:tree能進一步的描繪項目依賴樹,dependency:analyze能夠告訴你項目依賴潛在的問題,若是你有直接使用到的卻未聲明的依賴,該目標就會發出警告。maven-dependency-plugin還有不少目標幫助你操做依賴文件,例如dependency:copy-dependencies能將項目依賴從本地Maven倉庫複製到某個特定的文件夾下面。java

 

 

好比查看maven項目的依賴,咱們能夠用下面命令:node

mvn dependency:tree
以Dubbo的 dubbo-demo-provider 爲例,咱們輸入這個命令能夠得到下面信息:

mvn dependency:tree
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.alibaba:dubbo-demo-provider:jar:2.5.4-SNAPSHOT
[WARNING] '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
[WARNING] '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
[WARNING] '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
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]                                                                        
[INFO] ------------------------------------------------------------------------
[INFO] Building dubbo-demo-provider 2.5.4-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ dubbo-demo-provider ---
[INFO] com.alibaba:dubbo-demo-provider:jar:2.5.4-SNAPSHOT
[INFO] +- com.alibaba:dubbo-demo-api:jar:2.5.4-SNAPSHOT:compile
[INFO] +- com.alibaba:dubbo:jar:2.5.4-SNAPSHOT:compile
[INFO] |  \- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] +- org.springframework:spring:jar:2.5.6.SEC03:compile
[INFO] +- org.javassist:javassist:jar:3.15.0-GA:compile
[INFO] +- org.jboss.netty:netty:jar:3.2.5.Final:compile
[INFO] +- org.apache.mina:mina-core:jar:1.1.7:compile
[INFO] +- org.glassfish.grizzly:grizzly-core:jar:2.1.4:compile
[INFO] |  +- org.glassfish.grizzly:grizzly-framework:jar:2.1.4:compile
[INFO] |  |  \- org.glassfish.gmbal:gmbal-api-only:jar:3.0.0-b023:compile
[INFO] |  |     \- org.glassfish.external:management-api:jar:3.0.0-b012:compile
[INFO] |  +- org.glassfish.grizzly:grizzly-portunif:jar:2.1.4:compile
[INFO] |  \- org.glassfish.grizzly:grizzly-rcm:jar:2.1.4:compile
[INFO] +- org.apache.httpcomponents:httpclient:jar:4.1.2:compile
[INFO] |  +- org.apache.httpcomponents:httpcore:jar:4.1.2:compile
[INFO] |  \- commons-codec:commons-codec:jar:1.4:compile
[INFO] +- com.alibaba:fastjson:jar:1.1.39:compile
[INFO] +- com.thoughtworks.xstream:xstream:jar:1.4.1:compile
[INFO] |  +- xmlpull:xmlpull:jar:1.1.3.1:compile
[INFO] |  \- xpp3:xpp3_min:jar:1.1.4c:compile
[INFO] +- org.apache.bsf:bsf-api:jar:3.1:compile
[INFO] +- org.apache.zookeeper:zookeeper:jar:3.3.3:compile
[INFO] |  \- jline:jline:jar:0.9.94:compile
[INFO] +- com.github.sgroschupf:zkclient:jar:0.1:compile
[INFO] +- com.netflix.curator:curator-framework:jar:1.1.16:compile
[INFO] |  +- com.netflix.curator:curator-client:jar:1.1.16:compile
[INFO] |  \- com.google.guava:guava:jar:11.0.1:compile
[INFO] |     \- com.google.code.findbugs:jsr305:jar:1.3.9:compile
[INFO] +- com.googlecode.xmemcached:xmemcached:jar:1.3.6:compile
[INFO] +- org.apache.cxf:cxf-rt-frontend-simple:jar:2.6.1:compile
[INFO] |  +- org.apache.cxf:cxf-api:jar:2.6.1:compile
[INFO] |  |  +- org.codehaus.woodstox:woodstox-core-asl:jar:4.1.2:runtime
[INFO] |  |  |  \- org.codehaus.woodstox:stax2-api:jar:3.1.1:runtime
[INFO] |  |  +- org.apache.ws.xmlschema:xmlschema-core:jar:2.0.2:compile
[INFO] |  |  +- org.apache.geronimo.specs:geronimo-javamail_1.4_spec:jar:1.7.1:compile
[INFO] |  |  \- wsdl4j:wsdl4j:jar:1.6.2:compile
[INFO] |  +- org.apache.cxf:cxf-rt-core:jar:2.6.1:compile
[INFO] |  |  \- com.sun.xml.bind:jaxb-impl:jar:2.1.13:compile
[INFO] |  \- org.apache.cxf:cxf-rt-bindings-soap:jar:2.6.1:compile
[INFO] |     \- org.apache.cxf:cxf-rt-databinding-jaxb:jar:2.6.1:compile
[INFO] +- org.apache.cxf:cxf-rt-transports-http:jar:2.6.1:compile
[INFO] +- org.apache.thrift:libthrift:jar:0.8.0:compile
[INFO] |  \- commons-lang:commons-lang:jar:2.5:compile
[INFO] +- com.caucho:hessian:jar:4.0.7:compile
[INFO] +- javax.servlet:servlet-api:jar:2.5:compile
[INFO] +- org.mortbay.jetty:jetty:jar:6.1.26:compile
[INFO] |  +- org.mortbay.jetty:jetty-util:jar:6.1.26:compile
[INFO] |  \- org.mortbay.jetty:servlet-api:jar:2.5-20081211:compile
[INFO] +- log4j:log4j:jar:1.2.16:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.6.2:compile
[INFO] +- redis.clients:jedis:jar:2.1.0:compile
[INFO] |  \- commons-pool:commons-pool:jar:1.5.5:compile
[INFO] +- javax.validation:validation-api:jar:1.0.0.GA:compile
[INFO] +- org.hibernate:hibernate-validator:jar:4.2.0.Final:compile
[INFO] +- javax.cache:cache-api:jar:0.4:compile
[INFO] +- junit:junit:jar:4.10:test
[INFO] |  \- org.hamcrest:hamcrest-core:jar:1.1:test
[INFO] +- org.easymock:easymock:jar:3.0:test
[INFO] |  +- cglib:cglib-nodep:jar:2.2:test
[INFO] |  \- org.objenesis:objenesis:jar:1.2:test
[INFO] +- org.easymock:easymockclassextension:jar:3.0:test
[INFO] \- com.googlecode.jmockit:jmockit:jar:0.999.8:test
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.057 s
[INFO] Finished at: 2016-03-29T15:41:31+08:00
[INFO] Final Memory: 12M/309M
[INFO] ------------------------------------------------------------------------
git

 

unpack和copy相似,只不過它會把拷來的包解開,例如:github

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

spring

dependency:unpack 中經常使用參數有:apache

  • artifactItems:用來包含聲明須要解壓的文件元素;json

  • artifactItem:聲明須要解壓的文件;api

  • outputDirectory:定義解壓後輸出的文件夾;frontend

  • 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

相關文章
相關標籤/搜索