The mvn dependency:tree command prints a project's full dependency graph, including transitive dependencies, so you can see exactly what's being pulled into your build and why. It's the primary diagnostic tool for understanding and resolving Maven dependency issues.
Key Points: • Run it from the project root with mvn dependency:tree to print direct and transitive dependencies in a tree format. • Each entry shows the groupId, artifactId, version, and scope, making it easy to spot unexpected transitive versions. • It's the go-to tool for finding version conflicts, since Maven's "nearest wins" resolution can silently pick an unwanted version. • The -Dincludes or -Dexcludes flags let you filter the tree to a specific artifact of interest. • Combining it with dependency:analyze also helps identify unused or undeclared direct dependencies.
Example: If a project unexpectedly pulls in an old, vulnerable version of Jackson through a transitive dependency, running mvn dependency:tree -Dincludes=com.fasterxml.jackson.core quickly shows which parent dependency is dragging it in, so you can add an exclusion.
Code Example:
mvn dependency:tree -Dincludes=com.fasterxml.jackson.coreInterview Tip: A concise interview answer is:
"dependency:tree prints the full dependency graph for a project, direct and transitive, so I can see exactly which library is pulling in a conflicting or unwanted version. I use it constantly to debug version conflicts and to clean up dependencies before they cause runtime classpath issues."