Hi Gradle Team,
The new gradle release 5.4 includes a New API for Incremental Tasks
https://docs.gradle.org/current/javadoc/org/gradle/work/InputChanges.html
https://docs.gradle.org/current/dsl/org.gradle.work.InputChanges.html
The example provided in the above links doesnt work as expected
abstract class IncrementalReverseTask extends DefaultTask {
@Incremental
@InputDirectory
abstract DirectoryProperty getInputDir()
@OutputDirectory
abstract DirectoryProperty getOutputDir()
@TaskAction
void execute(InputChanges inputChanges) {
inputChanges.getFileChanges(inputDir).each { change ->
**// This is wrong once this code is executed further changes are not notified to this method**
// Example: when there is no history of previous execution (during first time run)
// All the files in the input directory along with the input directory should be notified to this method as ChangeType.ADDED
// However once the input directory is received as a change
// after the execution of return statement
// further file changes of the input directory are not reported back to this method
if (change.fileType == FileType.DIRECTORY) return
def targetFile = outputDir.file(change.normalizedPath).get().asFile
if (change.changeType == ChangeType.REMOVED) {
targetFile.delete()
} else {
targetFile.text = change.file.text.reverse()
}
}
}
}
The right code that is working for me is
abstract class IncrementalReverseTask extends DefaultTask {
@Incremental
@InputDirectory
abstract DirectoryProperty getInputDir()
@OutputDirectory
abstract DirectoryProperty getOutputDir()
@TaskAction
void execute(InputChanges inputChanges) {
inputChanges.getFileChanges(inputDir).each { change ->
if (change.fileType == FileType.FILE) {
def targetFile = outputDir.file(change.normalizedPath).get().asFile
if (change.changeType == ChangeType.REMOVED) {
targetFile.delete()
} else {
targetFile.text = change.file.text.reverse()
}
}
}
}
}
Please check and update accordingly
Or Please Let me know if I misunderstood the concept.