我目前正在使用Gradle 6.0进行实验,但遇到了一个问题,我想将cause语句与例如严格和拒绝的版本。
dependencies {
testImplementation(group: 'org.junit.jupiter', name: 'junit-jupiter-api') {
version {
strictly '[5.0, 6.0]'
prefer '5.5.2'
reject '5.5.1' // for testing purpose only
}
}
testRuntimeOnly(group: 'org.junit.jupiter', name: 'junit-jupiter-engine') {
version {
strictly '[5.0, 6.0]'
prefer '5.5.2'
reject '5.5.1' // for testing purpose only
}
}
// Force Gradle to load the JUnit Platform Launcher from the module-path
testRuntimeOnly(group: 'org.junit.platform', name: 'junit-platform-launcher') {
version {
strictly '[1.5, 2.0]'
prefer '1.5.2'
}
}
}
[我目前已尝试在because
语句的下方或上方添加version
语句,并在其周围添加大括号,但这些东西似乎都没有用。
是否可以将because
语句添加到最后一个依赖项,如果是,如何?知道是否可以将两个testRuntimeOnly
合并为一个也将很有趣。
使用Kotlin DSL,您可以轻松地确切地看到what对您可用。因此,将您的样本转换为使用Kotlin DSL,我们有
dependencies {
testImplementation("org.junit.jupiter", "junit-jupiter-api") {
version {
strictly("[5.0, 6.0]")
prefer("5.5.2")
reject("5.5.1") // for testing purpose only
}
}
testRuntimeOnly("org.junit.jupiter", "junit-jupiter-engine") {
version {
strictly("[5.0, 6.0]")
prefer("5.5.2")
reject("5.5.1") // for testing purpose only
}
}
// Force Gradle to load the JUnit Platform Launcher from the module-path
testRuntimeOnly("org.junit.platform", "junit-platform-launcher") {
version {
strictly("[1.5, 2.0]")
prefer("1.5.2")
}
}
}
是否可以将因为语句添加到最后一个依赖项,如果可以,如何添加?
是的。由于我现在正在使用Kotlin DSL,因此我可以轻松调出智能感:
您可以在这里看到because
可用外部 version
块,因此:
// Force Gradle to load the JUnit Platform Launcher from the module-path
testRuntimeOnly("org.junit.platform", "junit-platform-launcher") {
version {
strictly("[1.5, 2.0]")
prefer("1.5.2")
}
because("my reason here.")
}