mvn dependency:tree
Fast recall
Quick revision
Core answer
Knowledge of essential Maven diagnostic tooling—this is the first command experienced developers run when debugging dependency issues
Not knowing this command exists and manually searching pom files trying to understand dependency resolution
Mention filtering options like -Dincludes or -Dverbose to narrow down the output when searching for specific conflicts
Interview-ready guide
Interview answer
xml and all the transitive dependencies they pull in.
It's the first tool you should reach for when debugging dependency issues. The output is structured like a family tree. Your direct dependencies are at the root level, then indented beneath each one you see all the transitive dependencies it brought in, then indented further you see their transitive dependencies, and so on.
Each line shows the groupId, artifactId, version, and scope. This structure is critical because it tells you which dependency is responsible for each JAR on your classpath. Let's say you're getting a ClassNotFoundException for a Jackson class.
You run dependency:tree and search the output for jackson-databind. The tree shows you it's coming from spring-boot-starter-web, which is three levels deep. Now you know where it's coming from and can decide if you need to exclude it or upgrade it.
The command is also essential for debugging version conflicts. If two libraries depend on different versions of the same artifact, Maven has to pick one. The tree output shows you which version Maven selected and which it omitted, along with why—usually because of the nearest-wins rule.
For large projects, the output can be hundreds of lines, so you use filters. The -Dincludes option lets you narrow down to a specific library. slf4j colon asterisk shows only SLF4J-related dependencies and the paths that brought them in.
Another useful flag is -Dverbose, which shows even the dependencies Maven considered but didn't include, helping you understand conflict resolution.
A common mistake freshers make is not knowing this command exists. They face a NoSuchMethodError or find an unexpected library on their classpath and start randomly changing versions in their pom, hoping to fix it. Always run dependency:tree first—it shows you the actual state of your classpath, which is often very different from what you think it is just by looking at your pom.
mvn dependency:tree
Direct Answer
The mvn dependency:tree command displays the full hierarchical tree of all dependencies—both direct and transitive—showing which library pulls in each dependency. You use it to diagnose version conflicts, find unwanted transitive deps, and understand your actual classpath composition.
Code Example
// Run the command
// mvn dependency:tree
// Sample output (formatted for readability)
[INFO] com.example:order-service:jar:1.0.0
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:3.2.0:compile
[INFO] | +- org.springframework.boot:spring-boot-starter:jar:3.2.0:compile
[INFO] | | +- org.springframework.boot:spring-boot:jar:3.2.0:compile
[INFO] | | +- org.springframework.boot:spring-boot-autoconfigure:jar:3.2.0:compile
[INFO] | | \- org.springframework:spring-core:jar:6.1.1:compile
[INFO] | +- org.springframework:spring-web:jar:6.1.1:compile // depth 2
[INFO] | \- com.fasterxml.jackson.core:jackson-databind:jar:2.15.3:compile
[INFO] +- org.postgresql:postgresql:jar:42.6.0:runtime
[INFO] \- org.apache.commons:commons-lang3:jar:3.12.0:compile
[INFO] \- (conflict resolution)
// Filtering to specific library
// mvn dependency:tree -Dincludes=com.fasterxml.jackson.core:jackson-databind
// Output shows only paths that include Jackson
[INFO] com.example:order-service:jar:1.0.0
[INFO] \- org.springframework.boot:spring-boot-starter-web:jar:3.2.0:compile
[INFO] \- com.fasterxml.jackson.core:jackson-databind:jar:2.15.3:compile
[INFO] +- com.fasterxml.jackson.core:jackson-annotations:jar:2.15.3:compile
[INFO] \- com.fasterxml.jackson.core:jackson-core:jar:2.15.3:compile
Common Mistakes & Pitfalls
- Not using dependency:tree at all: Freshers face a ClassNotFoundException or version conflict and start randomly upgrading dependencies or adding exclusions without understanding the problem. Always run dependency:tree first to see what's actually on your classpath and where it came from.
- Ignoring the tree structure: Freshers look at the flat list of JARs and miss the indentation that shows parent-child relationships. The tree shows you which direct dependency caused each transitive dependency. If you need to exclude a library, you must exclude it from its parent, not add a global exclusion.
- Not filtering large output: Running dependency:tree on a Spring Boot project produces 500+ lines. Freshers get overwhelmed and give up. Use -Dincludes to focus on the specific library you're investigating, making the output manageable.
Check your understanding
Answer these without looking back at the article.
- How do you resolve a version conflict found in the dependency tree?
- What is the difference between mvn dependency:tree and mvn dependency:list?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.