Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View a dependency tree in Maven?

Tags:

I'd like to make sure I'm not including duplicate libraries in my Maven project. I'm pulling in quite a few dependencies from a few different repositories including main, Spring's repo, and JBoss' repository. How can I see a graph of the dependencies so I can make sure I'm not depending on multiple versions of a single library?

It would be kind of a bummer if I was including something like org.springframework:spring-core:3.0.1.RELEASE and org.springframework:org.springframework.spring-core:3.0.5.RELEASE which actually do show up as different dependencies, as weird as it sounds, because Spring's repository names things weirdly. What can I do to make sure I don't have duplicate dependencies?

like image 257
Naftuli Kay Avatar asked Jul 22 '11 22:07

Naftuli Kay


People also ask

How do I get Maven dependency tree?

How to get the Maven Dependency Tree of a Project. We can run mvn dependency:tree command in the terminal to print the project dependency tree. For our example, I will be using the Mockito Tutorial project. You can download the project from the GitHub repository.

How do you analyze a dependency tree in Maven?

A project's dependency tree can be filtered to locate specific dependencies. For example, to find out why Velocity is being used by the Maven Dependency Plugin, we can execute the following in the project's directory: mvn dependency:tree -Dincludes=velocity:velocity.

How do you check the dependency tree in Pom?

2) Find 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.

What is a dependency tree?

A dependency tree for a sentence is a directed acyclic graph with words as nodes and relations as edges. Each word in the sentence either modifies another word or is modified by a word. The root of the tree is the only entry that is modified but does not modify anything else.


1 Answers

The dependency:tree maven plugin should do what you want and show the tree.

Alternatively force Maven2 to copy dependencies into target/lib to copy the the artifacts in the target/lib directory which should also show duplicates but you would still need to grep all the POMs in the ~/.m2/repository to see which library is pulling in which version manually and that would be time consuming for large local repositories.

like image 59
andyb Avatar answered Oct 08 '22 08:10

andyb