How to get a dependency tree for an artifact?
Solution 1:
1) Use maven dependency plugin
Create a simple project with pom.xml only. Add your dependency and run:
mvn 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://search.maven.org/ 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 on this pom.
Solution 2:
If you bother creating a sample project and adding your 3rd party dependency to that, then you can run the following in order to see the full hierarchy of the dependencies.
You can search for a specific artifact using this maven command:
mvn dependency:tree -Dverbose -Dincludes=[groupId]:[artifactId]:[type]:[version]
According to the documentation:
where each pattern segment is optional and supports full and partial * wildcards. An empty pattern segment is treated as an implicit wildcard.
Imagine you are trying to find 'log4j-1.2-api' jar file among different modules of your project:
mvn dependency:tree -Dverbose -Dincludes=org.apache.logging.log4j:log4j-1.2-api
more information can be found here.
Edit: Please note that despite the advantages of using verbose parameter, it might not be so accurate in some conditions. Because it uses Maven 2 algorithm and may give wrong results when used with Maven 3.
Solution 3:
The solution is to call dependency:tree with the artifact's pom.xml file:
mvn -f "$HOME/.m2/repository/$POM_PATH" dependency:tree
See also How to list the transitive dependencies of an artifact from a repository?