【问题标题】:Is it possible to skip all gradle task with certain type?是否可以跳过特定类型的所有 gradle 任务?
【发布时间】:2020-05-02 01:02:20
【问题描述】:

我有一个 gradle 测试任务,设置如下 -

sourceSets {
    contractTest {
        compileClasspath += sourceSets.main.output
        runtimeClasspath += sourceSets.main.output
    }
}

configurations {
    contractTestImplementation.extendsFrom implementation
    contractTestRuntimeOnly.extendsFrom runtimeOnly
}

task contractTest(type: Test) {
    description = 'Runs contract tests.'
    group = 'verification'

    testClassesDirs = sourceSets.contractTest.output.classesDirs
    classpath = sourceSets.contractTest.runtimeClasspath
}

我希望在执行这样的命令后 - ./gradlew build -x test 以上任务(连同所有测试任务 - 单元、集成等)将被跳过。我可以通过在 gradlew 命令中明确提及 -x contractTest 来跳过此任务。有没有办法跳过与某种类型相关的所有任务?

【问题讨论】:

    标签: gradle


    【解决方案1】:

    -x(用于--exclude-task)标志允许您按名称而不是类型排除任务(请参阅Command-Line interface)。

    但是有一个更好的方法可以跳过所有“测试”任务:只需使用专用的check 生命周期任务:

    • 使check 任务依赖于您所有的自定义测试任务,

      check.dependsOn contractTest

    • 构建时排除check

      ./gradlew build -x check

    check 任务在这里描述:https://docs.gradle.org/current/userguide/java_plugin.html#lifecycle_tasks

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-22
      • 1970-01-01
      • 2014-06-06
      • 1970-01-01
      • 2018-08-26
      • 1970-01-01
      • 2012-11-28
      • 2013-08-25
      相关资源
      最近更新 更多