Incremental build support, limitations?


(Markus Kohler) #1

Hi all, I’m currently investigating the use of gradle for a large project and played around a bit with implementing incremental tasks.

I used the incrementalTask example in the userguide as a starting point and came up with the following build scripts that creates, reverses and reverses back a large number of files, see at the end of this post.

I think Ideally gradle should pass only the changed file to the second task, but in fact it does not seem to do that (I’m using the latest released version). Is there a way to achieve that, maybe in Gradle 2.0?


task originalInputs() << {

file(‘inputs’).mkdir()

for ( i in 0…9999 ) {

file(‘inputs/’+i+’.txt’).text = "Content for file "+i

}

}

task updateInputs() << {

file(‘inputs/1.txt’).text = “Changed content for existing file 1.”

file(‘inputs/4.txt’).text = “Content for new file 4.” }

task removeInput() << {

file(‘inputs/3.txt’).delete() }

task removeOutput() << {

file("$buildDir/outputs/1.txt").delete() }

task twice (dependsOn: [‘incrementalReverse2’,‘incrementalReverse’])<<{}

task incrementalReverse2(type: IncrementalReverseTask2) {

inputDir2 = file("$buildDir/outputs")

outputDir2 = file("$buildDir/outputs2")

inputProperty = project.properties[‘taskInputProperty’] ?: “original” }

task incrementalReverse(type: IncrementalReverseTask) {

inputDir = file(‘inputs’)

outputDir = file("$buildDir/outputs")

inputProperty = project.properties[‘taskInputProperty’] ?: “original” }

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”

inputs.outOfDate { change ->

println “out of date: ${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()

}

} }

class IncrementalReverseTask2 extends DefaultTask {

@InputDirectory

def File inputDir2

@OutputDirectory

def File outputDir2

@Input

def inputProperty

@TaskAction

void execute(IncrementalTaskInputs inputs) {

println inputs.incremental ? “CHANGED inputs considered out of date” : “ALL inputs considered out of date”

inputs.outOfDate { change ->

println “out of date: ${change.file.name}”

def targetFile = new File(outputDir2, change.file.name)

targetFile.text = change.file.text.reverse()

}

inputs.removed { change ->

println “removed: ${change.file.name}”

def targetFile = new File(outputDir2, change.file.name)

targetFile.delete()

}

} }

Note that for my small example the performance is still ok. E.g. below 1.5 seconds for 10000 files on my machine.

Regards, Markus