我在 pom.xml 中排除了 junit 依赖项的 hamcrest 依赖项。
当我比较运行 "mvn package"
和 "mvn dependency:tree"
时的日志时,我在排除 hamcrest 依赖之前和之后没有看到任何差异。
这里是排除传递依赖的部分。在哪里可以找到运行排除部分之前和之后的差异?我还查看了 .m2 目录
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
<exclusions>
</exclusion>
<groupId> org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
</exclusion>
</exclusions>
</dependency>
最佳答案
正如 Kiril S. 所说,由于拼写错误,显示的 pom 部分无效,这会导致执行任何任务时出现错误。
排除是错误的,因为它确实与 junit 声明的任何依赖项匹配。
运行 mvn dependency:tree
应显示以下内容:
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ my-app ---
[INFO] com.mycompany.app:my-app:jar:1.0-SNAPSHOT
[INFO] \- junit:junit:jar:4.11:test
[INFO] \- org.hamcrest:hamcrest-core:jar:1.3:test
如您所见,junit 的实际依赖项是
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
如果您在 pom 中修复了该问题,则调用 mvn dependency:tree
将导致预期的排除。
[INFO] com.mycompany.app:my-app:jar:1.0-SNAPSHOT
[INFO] \- junit:junit:jar:4.11:test
[INFO] ------------------------------------------------------------------------
关于java - Maven,排除 junit 的 hamcrest 依赖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35027292/