Skip to content

/commands/maven/mvn-dependency-tree

mvn dependency:tree: show the Maven dependency tree and find conflicts

The commands on this page have not been executed by our verification runner yet.updated
tool
Maven
versions
Maven 3.x, maven-dependency-plugin 3.x
os
any

mvn dependency:tree prints the resolved dependency tree of the project: each direct dependency with the transitive dependencies it brings, their versions and scopes. Use it to answer "where does this library come from?" and "why is this version used?". Run it from the folder with pom.xml; in a multi-module build it prints one tree per module.

Usage

bash
mvn dependency:tree
mvn dependency:tree -Dincludes=com.fasterxml.jackson.core     # only paths to Jackson core
mvn dependency:tree -Dincludes=org.slf4j:slf4j-api            # groupId:artifactId
mvn dependency:tree -Dverbose                                  # also omitted duplicates and conflicts
mvn dependency:tree -Dscope=runtime                            # one scope
mvn dependency:tree -DoutputFile=tree.txt                      # write to a file
mvn -pl api dependency:tree                                    # one module of a multi-module build

Reading the output

text
[INFO] com.example:app:jar:1.0.0
[INFO] +- org.springframework:spring-web:jar:6.1.5:compile
[INFO] |  +- org.springframework:spring-beans:jar:6.1.5:compile
[INFO] |  \- io.micrometer:micrometer-observation:jar:1.12.4:compile
[INFO] \- org.junit.jupiter:junit-jupiter:jar:5.10.2:test

Each line is groupId:artifactId:type:version:scope. +- and \- mark a child and the last child of a node; indentation shows depth. The example above is illustrative; your output depends on your pom.xml.

OptionEffect
-Dincludes=PATTERNShow only paths that lead to matching artifacts ([groupId]:[artifactId]:[type]:[version], wildcards allowed)
-Dexcludes=PATTERNHide matching artifacts
-DverboseInclude dependencies omitted for duplicates or conflicts, with the reason
-Dscope=SCOPEOnly dependencies in that scope (compile, runtime, test...)
-DoutputFile=FILEWrite the tree to FILE instead of the log
-DoutputType=dot|graphml|tgf|jsonMachine-readable formats (json in recent plugin versions)

Fixing a version conflict

Maven picks the version nearest to your project in the tree (first declaration wins at equal depth). To force a version, declare it in <dependencyManagement>, or exclude the unwanted transitive copy:

pom.xml
<dependency>
  <groupId>org.example</groupId>
  <artifactId>library</artifactId>
  <version>2.0.0</version>
  <exclusions>
    <exclusion>
      <groupId>commons-logging</groupId>
      <artifactId>commons-logging</artifactId>
    </exclusion>
  </exclusions>
</dependency>

Run mvn dependency:tree -Dincludes=commons-logging again to confirm the path is gone. Gradle's equivalent is gradle dependencies and dependencyInsight.

Sources