我正在使用 Gradle 5 的 BOM(物料清单)feature https://docs.gradle.org/5.0/userguide/managing_transitive_dependencies.html#sec:bom_import。这是我对 JUnit 5 依赖项的描述:
testImplementation(enforcedPlatform("org.junit:junit-bom:5.4.0")) // JUnit 5 BOM
testImplementation("org.junit.jupiter:junit-jupiter-api")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
testImplementation("org.junit.jupiter:junit-jupiter-params")
我的假设是提供 BOM 将解析依赖项的版本5.4.0
。然而,他们决心5.1.1
。我不知道为什么。 (我还要求enforcedPlatform()
锁定指定版本)
检验JUnit 5 的 BOM http://central.maven.org/maven2/org/junit/junit-bom/5.4.0/junit-bom-5.4.0.pom我们看到所有org.junit.jupiter
列出了依赖项和版本5.4.0
(解决项目中的5.1.1)以及所有org.junit.platform
列出了依赖项和版本1.4.0
在项目中正确解决。
我不确定我错过了什么,希望在这里得到一些帮助。谢谢!
EDIT:
我使用了 Sormuras 响应并将所有 BOM 移到了顶部dependencies {}
阻止但仍未获得版本5.4.0
。然后我怀疑它可能来自Gradle Spring 依赖管理 https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/html/#managing-dependencies我使用的插件,所以当我将其注释掉时,我得到了版本 JUnit 5.4.0。如何禁用来自 Gradle Spring 依赖管理插件的 JUnit?
FINALLY:
我决定使用Spring Boot 依赖项 BOM https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-dependencies直接删除 Gradle 插件:
implementation(platform("org.springframework.boot:spring-boot-dependencies:2.0.5.RELEASE"))
我想该插件是为 Gradle 5 之前的 Gradle 版本创建的,其中您无法使用 BOM 文件。现在有了 BOM 支持,我可以直接包含它。这样我的 JUnit 版本就是我在enforcedPlatform()
block.
我接受了 Sam Brannen 下面的回答,因为他很好地解释了问题是如何发生的以及如何解决它,我认为这对于那些使用旧版本 Gradle 的人来说是相关的。