71

Is there a CLI tool I can use to quickly view the transitive dependencies of a Maven pom.xml file?

BuZZ-dEE
  • 6,075
  • 12
  • 66
  • 96
ryan
  • 5,039
  • 13
  • 35
  • 42
  • 1
    Possible duplicate of [How to get a dependency tree for an artifact?](https://stackoverflow.com/questions/3342908/how-to-get-a-dependency-tree-for-an-artifact) – Kayvan Tehrani Apr 15 '18 at 12:38

1 Answers1

122

On the CLI, use mvn dependency:tree
(Here are some additional Usage notes)

When running dependency:tree on multi-module maven project, use mvn compile dependency:tree instead1.

Otherwise, the POM Editor in M2Eclipse (Maven integration for Eclipse) is very good, and it includes a hierarchical dependency view.


1If you don't compile, you might get error Failed to execute goal on project baseproject: Could not resolve dependencies for project com.company:childproject:jar:1.0.0: Could not find artifact. This might happen because dependency:tree command doesn't build projects and doesn't resolve dependencies, and your projects are not installed in maven repository.

izogfif
  • 6,000
  • 2
  • 35
  • 25
Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
  • 4
    That's not really practical if you're trying to identify which transitive dependencies you are relying on at compile time. It just gives you a giant list of all transitive dependencies, used or not. – Sridhar Sarnobat Oct 03 '17 at 18:21
  • 9
    Also, to see conflict resolution among transitive dependencies, you will need to add verbose: mvn dependency:tree -Dverbose ``https://maven.apache.org/plugins/maven-dependency-plugin/examples/resolving-conflicts-using-the-dependency-tree.html`` – kisna Mar 20 '18 at 00:49
  • 3
    I think the verbose option suggested by @kisna is essential - otherwise, repeated transitive dependencies will not be drawn. – flow2k Jun 25 '19 at 21:55
  • 1
    Another caveat: if a project uses the Shade plugin, `dependency:tree` may not be able to draw its transitive dependencies. – flow2k Jun 25 '19 at 21:57