maven依赖冲突解决
Maven Dependency Tree is very helpful in understanding the project dependencies and resolving any conflicts because of different versions of a dependency.
Maven依赖关系树对于理解项目依赖关系和解决由于依赖关系版本不同而引起的任何冲突非常有帮助。
如何获取项目的Maven依赖树 (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.
我们可以在终端中运行mvn dependency:tree
命令以打印项目依赖关系树。
For our example, I will be using the Mockito Tutorial project. You can download the project from the GitHub repository.
对于我们的示例,我将使用Mockito Tutorial项目。 您可以从GitHub存储库下载项目。
We are interested only in the project dependencies. The pom.xml has declared the following project dependencies.
我们仅对项目依赖项感兴趣。 pom.xml声明了以下项目依赖项。
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>1.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>2.19.0</version>
<scope>test</scope>
</dependency>
<!-- TestNG Dependencies -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<scope>test</scope>
</dependency>
</dependencies>
Let’s see the output when we run the maven dependency tree command.
让我们看看运行maven依赖树命令时的输出。
$ mvn dependency:tree
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------------------
[INFO] Building Mockito-Examples 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ Mockito-Examples ---
[INFO] com.journaldev.mockito:Mockito-Examples:jar:1.0-SNAPSHOT
[INFO] +- org.junit.platform:junit-platform-runner:jar:1.2.0:test
[INFO] | +- org.apiguardian:apiguardian-api:jar:1.0.0:test
[INFO] | +- org.junit.platform:junit-platform-launcher:jar:1.2.0:test
[INFO] | +- org.junit.platform:junit-platform-suite-api:jar:1.2.0:test
[INFO] | | \- org.junit.platform:junit-platform-commons:jar:1.2.0:test
[INFO] | \- junit:junit:jar:4.12:test
[INFO] | \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] +- org.junit.jupiter:junit-jupiter-engine:jar:5.2.0:test
[INFO] | +- org.junit.platform:junit-platform-engine:jar:1.2.0:test
[INFO] | | \- org.opentest4j:opentest4j:jar:1.1.0:test
[INFO] | \- org.junit.jupiter:junit-jupiter-api:jar:5.2.0:test
[INFO] +- org.mockito:mockito-junit-jupiter:jar:2.19.0:test
[INFO] | \- org.mockito:mockito-core:jar:2.19.0:test
[INFO] | +- net.bytebudd