dependency command

$ mvn dependency:tree

Displays in form of a tree view all the dependencies of a given project, and also the dependencies of the dependencies (transative dependencies)

Example output

com.mkyong.common:spring-mvc-logback:war:1.0-SNAPSHOT
+- org.springframework:spring-core:jar:4.1.6.RELEASE:compile
+- org.springframework:spring-webmvc:jar:4.1.6.RELEASE:compile
|  +- org.springframework:spring-beans:jar:4.1.6.RELEASE:compile
|  +- org.springframework:spring-context:jar:4.1.6.RELEASE:compile
|  |  \- org.springframework:spring-aop:jar:4.1.6.RELEASE:compile
|  |     \- aopalliance:aopalliance:jar:1.0:compile
|  +- org.springframework:spring-expression:jar:4.1.6.RELEASE:compile
|  \- org.springframework:spring-web:jar:4.1.6.RELEASE:compile
+- org.slf4j:jcl-over-slf4j:jar:1.7.12:compile
|  \- org.slf4j:slf4j-api:jar:1.7.12:compile
+- ch.qos.logback:logback-classic:jar:1.1.3:compile
|  \- ch.qos.logback:logback-core:jar:1.1.3:compile

Filtering the dependency tree

A project's dependency tree can be filtered to locate specific dependencies. For example, to find out why Velocity is being used by the Maven Dependency Plugin, we can execute the following in the project's directory:

mvn dependency:tree -Dincludes=velocity:velocity

Which outputs:

[INFO] [dependency:tree]
[INFO] org.apache.maven.plugins:maven-dependency-plugin:maven-plugin:2.0-alpha-5-SNAPSHOT
[INFO] \- org.apache.maven.doxia:doxia-site-renderer:jar:1.0-alpha-8:compile
[INFO]    \- org.codehaus.plexus:plexus-velocity:jar:1.1.3:compile
[INFO]       \- velocity:velocity:jar:1.4:compile

Thus we can see that Velocity is being brought in by Plexus Velocity, which in turn is being brought in by a direct dependency on Doxia Site Renderer.

The syntax for filter patterns is as follows:

[groupId]:[artifactId]:[type]:[version]

Resolving conflicts using the dependency tree

mvn dependency:tree -Dverbose

Prints the dependency conflicts. A project's dependency tree can be expanded to display dependency conflicts. For example, to find out why Commons Collections 2.0 is being used by the Maven Dependency Plugin, we can execute the following in the project's directory:

mvn dependency:tree -Dverbose -Dincludes=commons-collections

The verbose flag instructs the dependency tree to display conflicting dependencies that were omitted from the resolved dependency tree. In this case, the goal outputs:

[INFO] [dependency:tree]
[INFO] org.apache.maven.plugins:maven-dependency-plugin:maven-plugin:2.0-alpha-5-SNAPSHOT
[INFO] +- org.apache.maven.reporting:maven-reporting-impl:jar:2.0.4:compile
[INFO] |  \- commons-validator:commons-validator:jar:1.2.0:compile
[INFO] |     \- commons-digester:commons-digester:jar:1.6:compile
[INFO] |        \- (commons-collections:commons-collections:jar:2.1:compile - omitted for conflict with 2.0)
[INFO] \- org.apache.maven.doxia:doxia-site-renderer:jar:1.0-alpha-8:compile
[INFO]    \- org.codehaus.plexus:plexus-velocity:jar:1.1.3:compile
[INFO]       \- commons-collections:commons-collections:jar:2.0:compile

Thus we can see that Commons Collections 2.0 was chosen over 2.1 since it is nearer, and by default Maven resolves version conflicts with a nearest-wins strategy

Purging local repository dependencies

The purpose of the dependency:purge-local-repository goal is to purge (delete and optionally re-resolve) artifacts from the local maven repository. This page describes some of the configuration options available to the plugin.
The default behaviour of the plugin is to first resolve the entire dependency tree, then delete the contents from the local repository, and then re-resolve the dependencies from the remote repository.

mvn dependency:purge-local-repository

By default, the plugin operates on all transitive dependencies. This means that the plugin may download certain missing dependencies to gather the full dependency tree information before beginning the purge process.
To avoid this pre-download step, the plugin can be configured to operate only on the direct dependencies of the project using the "actTranstively" parameter.

mvn dependency:purge-local-repository -DactTransitively=false

ocid1.compartment.oc1..aaaaaaaatqvquddgcywqlx7yuv2iwcskgc2yca6za4wme22dwecnkdm2hnaa