Gradle 6依赖项具有严格的版本,因为关键字

问题描述 投票:0回答:1

问题

我目前正在使用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合并为一个也将很有趣。

gradle groovy build.gradle dependency-management
1个回答
0
投票

使用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,因此我可以轻松调出智能感:

intelli-sense

您可以在这里看到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.")
}
© www.soinside.com 2019 - 2024. All rights reserved.