maven-2build-processdependencies

How to get a dependency tree for an artifact?


dependency:tree can be used to see the dependency tree for a given project. But what I need is to see the dependency tree for a 3rd party artifact.

I guess I can create an empty project, but I'm looking for something easier (I need to do this for several artifacts).


Solution

  • 1) Use maven dependency plugin

    Create a simple project with pom.xml only. Add your dependency and run:

    mvn dependency:tree
    

    (Version for multi-module Maven project: mvn compile dependency:tree )

    Unfortunately dependency mojo must use pom.xml or you get following error:

    Cannot execute mojo: tree. It requires a project with an existing pom.xml, but the build is not using one.

    2) Find pom.xml of your artifact in maven central repository

    Dependencies are described In pom.xml of your artifact. Find it using maven infrastructure.

    Go to https://central.sonatype.com and enter your groupId and artifactId.

    Or you can go to https://repo1.maven.org/maven2/ and navigate first using plugins groupId, later using artifactId and finally using its version.

    For example see org.springframework:spring-core

    3) Use maven dependency plugin against your artifact

    Part of dependency artifact is a pom.xml. That specifies it's dependency. And you can execute mvn dependency:tree -f <your-pom-filename> on this pom.