问题所在
我目前正在试验Gradle 6.0,并遇到了一个问题,我想将for语句与语法结合起来,例如,严格的版本和拒绝的版本。
我的建筑剧本:
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合并为一个,这也会很有趣。
发布于 2019-11-16 17:04:08
使用Kotlin DSL,您可以很容易地看到为您提供了什么。因此,将您的示例转换为使用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")
}
}
}是否可以在最后一个依赖项中添加last语句,如果可以,如何添加?
是的。由于我现在使用的是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.")
}https://stackoverflow.com/questions/58886733
复制相似问题