【问题标题】:Gradle 6 dependencies with strict version and because keyword具有严格版本和因为关键字的 Gradle 6 依赖项
【发布时间】:2020-03-12 04:19:06
【问题描述】:

问题

我目前正在试验 Gradle 6.0,遇到了一个问题,我想将因为语句与例如语法结合起来。严格和拒绝的版本。

我的构建脚本:

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'
        }
    }
}

到目前为止我已经尝试过什么

我目前尝试在versionstatement 下方或上方添加because 语句,并在它们周围添加大括号,但这些事情似乎都没有奏效。

问题

是否可以将because 语句添加到最后一个依赖项,如果可以,如何? 知道我是否可以将两个testRuntimeOnly 合二为一也很有趣。

【问题讨论】:

    标签: gradle groovy build.gradle dependency-management


    【解决方案1】:

    使用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")
            }
        }
    }
    

    是否可以将因为语句添加到最后一个依赖项,如果可以,如何?

    是的。由于我现在使用的是 Kotlin DSL,我可以轻松调出智能感知:

    您可以在这里看到becauseversion 块之外可用,所以:

    // 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.")
    }
    

    【讨论】:

      猜你喜欢
      • 2021-10-09
      • 1970-01-01
      • 2017-08-21
      • 2017-08-29
      • 1970-01-01
      • 1970-01-01
      • 2018-06-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多