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.

Filter pattern syntax

The syntax for filter patterns is as follows:

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

Where each pattern segment is optional and supports full and partial * wildcards. An empty pattern segment is treated as an implicit wildcard.

For example, org.apache.* would match all artifacts whose group id started with org.apache., and :::*-SNAPSHOT would match all snapshot artifacts.

Excluding dependencies from the tree

The dependency tree can also be filtered to remove specific dependencies. For example, to exclude Plexus dependencies from the tree, we can execute the following:

mvn dependency:tree -Dexcludes=org.codehaus.plexus

Specifying multiple patterns

Multiple patterns can be specified when filtering the dependency tree by separating the patterns with commas. For example, to exclude Maven and Plexus dependencies from the tree, we can execute the following:

mvn dependency:tree -Dexcludes=org.apache.maven*,org.codehaus.plexus

Including and excluding dependencies from the tree

Both include and exclude patterns and be specified together to filter the dependency tree. For example, to locate all non-snapshot Plexus dependencies in the tree, we can execute the following:

mvn dependency:tree -Dincludes=org.codehaus.plexus -Dexcludes=:::*-SNAPSHOT