Gradle:在任务最新时排除(不跳过)任务

时间:2014-07-29 14:44:34

标签: gradle

我正在寻找一种方法来避免运行最新任务的依赖关系(同时仍然运行任何与其他任务相关的任务,而不是最新的任务)。

采取以下结构:

task stopService {}
task startService {}
task doUpdateA { // change something about the service }
task doUpdateB { // change something else about the service }

task updateA {
    inputs.files <some inputs>
    output.upToDateWhen { true }
    // i.e. run whenever inputs changed from previous run

    dependsOn stopService
    dependsOn doUpdateA
    dependsOn startService

    // ensure the service is stopped while it's being modified
    doUpdateA.mustRunAfter stopService
    startService.mustRunAfter doUpdateA
}


task updateB {
    inputs.files <some inputs>
    output.upToDateWhen { true }
    // i.e. run whenever inputs changed from previous run

    dependsOn stopService
    dependsOn doUpdateB
    dependsOn startService

    // ensure the service is stopped while it's being modified
    doUpdateB.mustRunAfter stopService
    startService.mustRunAfter doUpdateB
}

task updateAll {
    dependsOn updateA
    dependsOn updateB
}

./gradlew updateAll所需的执行流程:

  • 如果updateA和updateB都是最新的,则不执行任何操作
  • 如果其中一个不是最新的,stopService -> doUpdateX -> startService
  • 如果两者都不是最新的,stopService -> doUpdateA -> doUpdateB -> startService(或A之前的B)。

这是否可能,可能是通过挂钩任务执行图并在所有任务上手动运行upToDate,如果它们是最新的则排除它们?假设没有任务使另一个任务过时。

----半解决方案:

如果我忽略了第三个要求,可以通过以下方式解决这个问题:     任务更新B {         inputs.files         output.upToDateWhen {true}         //即每当输入从之前的运行中改变时运行

    doLast {
        stopService.execute()
        doUpdateB.execute()
        startService.execute()
    }
}

但由于几个原因这是次优的 - 不会运行stop / startService的依赖关系/终结者(我认为?),每次更新都会导致单独停止/启动(使构建时间更长)等等。

如果忽略要求1,则类似:

task updateAll {
    inputs.files <some inputs>
    output.upToDateWhen { true }
    // i.e. run whenever inputs changed from previous run

    dependsOn stopService
    dependsOn doUpdateA
    dependsOn doUpdateB
    dependsOn startService

    doUpdateB.mustRunAfter stopService
    startService.mustRunAfter doUpdateB
    doUpdateA.mustRunAfter stopService
    startService.mustRunAfter doUpdateA
}

将最新检查移至doUpdateX工作,但由于此边距太短而无法包含,因此再次是次优的。

提前感谢任何建议,

0 个答案:

没有答案