我的build.gradle文件中有一个javaexec任务,顺序处理超过100个文件。我想为此任务添加增量构建行为。
请告诉我如何为自定义JavaExec
任务实施此增量功能。
答案 0 :(得分:0)
I have tried the following:
class IncrementalReverseTask extends DefaultTask {
@InputDirectory
def File inputDir
@OutputDirectory
def File outputDir
@Input
def inputProperty
@TaskAction
void execute(IncrementalTaskInputs inputs) {
println inputs.incremental ? "CHANGED inputs considered out of date"
: "ALL inputs considered out of date"
if (!inputs.incremental)
project.delete(outputDir.listFiles())
inputs.outOfDate { change ->
println "Modified: ${change.file.name}"
def targetFile = new File(outputDir, change.file.name)
targetFile.text = change.file.text.reverse()
}
inputs.removed { change ->
println "removed: ${change.file.name}"
def targetFile = new File(outputDir, change.file.name)
targetFile.delete()
}
}
}
then create a task like this
task incrementalReverse(type: IncrementalReverseTask) {
inputDir = file('resource/inputs')
outputDir = file('resource/outputs')
inputProperty = project.properties['taskInputProperty'] ?: "original"
}
The above incremental task checks for changes in files in inputs folder.