In-depth analysis of Maven dependency tree: a guide to conflict resolution and optimization strategies
About 415 wordsAbout 1 minDecember 4, 2024
The dependency:tree
command is used to view all dependencies in a project, including direct and transitive dependencies.
Maven Dependency Tree Command
mvn dependency:tree
This command generates a dependency tree that includes all direct and transitive dependencies and outputs it to the terminal.
Assuming your project's pom.xml
file contains the following dependency:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.2.9.RELEASE</version>
</dependency>
Running mvn dependency:tree
might produce output similar to the following:
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ my-project ---
[INFO] my-project:jar:1.0-SNAPSHOT
[INFO] +- org.springframework:spring-core:jar:5.2.9.RELEASE:compile
[INFO] | \- org.springframework:spring-jcl:jar:5.2.9.RELEASE:compile
[INFO] \- junit:junit:jar:4.12:test
In this example, spring-core
depends on spring-jcl
, and my-project
also directly depends on junit
.
Filtering the Dependency Tree
If you want to view only specific dependencies, you can use the -Dincludes
and -Dexcludes
parameters to filter the dependency tree. For example, to view only spring
related dependencies, you can run the following command:
mvn dependency:tree -Dincludes=org.springframework