Wednesday, March 2, 2011

How to get the transitive dependency list using Maven

You may need to find the list of transitive dependencies, so that you can exclude unnecessary dependencies. Add the following maven plugin

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

Use dependency:tree as the goal.

mvn clean install dependency:tree

If maven fails with some error, then, use dependency:tree as the goal with -X option.

mvn clean install dependency:tree -X

Sample:

com.hp.hpl.jena.wso2:arq:bundle:1.0.0.wso2v1
+- com.ibm.icu:icu4j:jar:3.8:compile
\- com.hp.hpl.jena:arq:jar:2.8.3:compile
   +- com.hp.hpl.jena:jena:jar:2.6.2:compile
   |  +- org.slf4j:slf4j-log4j12:jar:1.5.6:runtime
   |  \- log4j:log4j:jar:1.2.13:runtime
   +- com.hp.hpl.jena:iri:jar:0.8:compile
   +- org.codehaus.woodstox:wstx-asl:jar:3.2.9:compile
   |  \- stax:stax-api:jar:1.0.1:compile
   +- org.apache.lucene:lucene-core:jar:2.3.1:compile
   +- junit:junit:jar:3.8.1:compile (version managed from 4.5)
   +- org.slf4j:slf4j-api:jar:1.5.8:compile
   \- xerces:xercesImpl:jar:2.7.1:compile
------------------------------------------------------------------------

3 comments:

  1. Very useful - you can even shorten it a bit and just use "mvn dependency:tree" ;)

    ReplyDelete
  2. If your build fails because there's a unresolvable dependency, dependency:tree won't produce any output.
    You need the -X to get the result anyway.

    ReplyDelete