Ton*_*ony 5 build gradle incremental-build build.gradle
为了让增量构建支持在 gradle 中正确运行,需要在每个(自定义)任务中定义“输入”和“输出”。
这是一种非常简洁的 gradle 方法来检查任务是否可以因为它是最新的而被跳过。样本:
task myTaskA {
def someOutputDir = file("$buildDir/gen")
// define task outputs (input not required here)
outputs.dir someOutputDir
doLast{
// generate something into the defined output directory
new File(someOutputDir, "dummy.txt").text = "Gradle sample"
}
}
task myTaskB {
// Input of this task is dependent on the output of myTaskA
inputs.files myTaskA
doLast{
// do something
}
}
Run Code Online (Sandbox Code Playgroud)
是的,这非常好,另外好处是,我们不需要在任务“myTaskB”中声明显式依赖指令(dependsOn)。
dependsOn myTaskA
Run Code Online (Sandbox Code Playgroud)
该指令不是必需的,因为我们有由输入声明定义的隐式依赖项。
我认为在自定义任务中始终提供输入/输出定义以支持增量构建是一种很好的风格。
但是:这也意味着我们可以完全忽略 dependentOn。
SO:我们什么时候应该dependsOn选择inputs/outputs?
也许如果没有输入或输出。是的,但是还有其他可以想到的用例吗?我一直在使用dependsOn,而这对我来说现在已经过时了。你怎么认为?
| 归档时间: |
|
| 查看次数: |
3166 次 |
| 最近记录: |