【发布时间】:2019-07-03 01:17:56
【问题描述】:
我正在使用 Gradle 5 的 BOM(材料清单)feature。这就是我对 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's BOM,我们看到所有org.junit.jupiter 依赖项都以5.4.0 版本列出(在项目中解析为5.1.1),所有org.junit.platform 依赖项都以1.4.0 版本列出,它们在项目。
我不确定我错过了什么,并希望在这里得到一些帮助。谢谢!
编辑:
我使用了 Sormuras 响应并将所有 BOM 移动到 dependencies {} 块的顶部,但仍然没有得到版本 5.4.0。然后我怀疑它可能来自我使用的Gradle Spring Dependency Management 插件,所以当我注释掉它时,我得到了 JUnit 5.4.0 版本。如何禁用来自 Gradle Spring 依赖管理插件的 JUnit?
终于:
我决定直接使用Spring Boot Dependencies BOM 并移除 Gradle 插件:
implementation(platform("org.springframework.boot:spring-boot-dependencies:2.0.5.RELEASE"))
我想该插件是为 Gradle 5 之前的 Gradle 版本创建的,您无法使用 BOM 文件。现在有了 BOM 支持,我可以直接包含它。这样我的 JUnit 版本就像我在 enforcedPlatform() 块中指定的那样。
我在下面接受了 Sam Brannen 的回答,因为他很好地解释了问题是如何发生的以及解决问题的方法,我认为这与使用旧版本 Gradle 的人相关。
【问题讨论】:
-
./gradlew dependencyInsight --dependency junit-jupiter-api --configuration testCompileClasspath打印什么? -
@MarcPhilipp imgur.com/dGBFyxf
标签: spring-boot gradle junit junit5