java - 为什么 hamcrest 出现在我的类(class)路径中?

标签 java intellij-idea gradle junit hamcrest

我已将 gradle 与 intellij 集成,但我似乎无法弄清楚为什么 hamcrest 库位于我的类路径中,即使它未在 build.gradle 中列出。

enter image description here

最佳答案

因为 junit:junit:4.12 将其作为传递依赖项引入。您可以通过运行看到这一点

./gradlew dependencies

这是 jUnit 文档中的相关部分

There is nothing extra that needs to be done in order to use a specific artifact of Hamcrest. In the past, there were two JUnit Maven artifacts: junit:junit and junit:junit-dep, where the latter version did not include a bundled copy of org.hamcrest:hamcrest-core and instead declared a transitive dependency on Hamcrest. In order to be more Maven-like, starting in version 4.11, there is only the junit:junit artifact which uses a transitive dependency on hamcrest-core.

https://github.com/junit-team/junit4/wiki/Use-with-Gradle

关于java - 为什么 hamcrest 出现在我的类(class)路径中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39859603/

相关文章:

java - 通过 XML 记录进行复杂的搜索查询

java - 如果碰巧内存不足,是否可以监控jboss?

java - 将 Clojure WAR Web 应用程序部署到 Tomcat 后提取的结果应该是什么?

java - 如何将文件从sources目录移动到IntelliJ IDEA中具有相同路径的resources目录?

java - java.lang.ClassNotFoundException未指定缺少的类

java - 如何使用 mapstruct 将枚举转换为 POJO?

intellij-idea - 在 IntelliJ 中完全禁用自动导入

intellij-idea - IntelliJ/WebStorm "Smart"换行缩进/Tab

android - 顶级 build.gradle 文件中的 ext 属性

android - flutter : can't build android in debug or release