@NonExtensible public interface IncrementalTaskInputs
An incremental task action is one that accepts a single IncrementalTaskInputs
parameter.
The task can then provide an action to execute for all input files that are out of date with respect to the previous execution of the task,
and a separate action for all input files that have been removed since the previous execution.
class IncrementalReverseTask extends DefaultTask { @InputDirectory def File inputDir @OutputDirectory def File outputDir @TaskAction void execute(IncrementalTaskInputs inputs) { if (!inputs.incremental) { project.delete(outputDir.listFiles()) } inputs.outOfDate { change -> def targetFile = project.file("$outputDir/${change.file.name}") targetFile.text = change.file.text.reverse() } inputs.removed { change -> def targetFile = project.file("$outputDir/${change.file.name}") if (targetFile.exists()) { targetFile.delete() } } } }
In the case where Gradle is unable to determine which input files need to be reprocessed, then all of the input files will be reported as outOfDate(org.gradle.api.Action<? super org.gradle.api.tasks.incremental.InputFileDetails>)
.
Cases where this occurs include:
TaskOutputs.upToDateWhen(groovy.lang.Closure)
criteria added to the task returns false
.Input
property has changed since the previous execution.outOfDate(org.gradle.api.Action<? super org.gradle.api.tasks.incremental.InputFileDetails>)
and removed(org.gradle.api.Action<? super org.gradle.api.tasks.incremental.InputFileDetails>)
can each only be executed a single time per IncrementalTaskInputs
instance.outOfDate(org.gradle.api.Action<? super org.gradle.api.tasks.incremental.InputFileDetails>)
must be executed before removed(org.gradle.api.Action<? super org.gradle.api.tasks.incremental.InputFileDetails>)
is called.Modifier and Type | Method | Description |
---|---|---|
boolean |
isIncremental() |
Indicates if it was possible for Gradle to determine which input files were out of date compared to a previous execution.
|
void |
outOfDate(Action<? super InputFileDetails> outOfDateAction) |
Executes the action for all of the input files that are out-of-date since the previous task execution.
|
void |
removed(Action<? super InputFileDetails> removedAction) |
Executes the action for all of the input files that were removed since the previous task execution.
|
boolean isIncremental()
When true
:
outOfDate(org.gradle.api.Action<? super org.gradle.api.tasks.incremental.InputFileDetails>)
.removed(org.gradle.api.Action<? super org.gradle.api.tasks.incremental.InputFileDetails>)
.
When false
:
outOfDate(org.gradle.api.Action<? super org.gradle.api.tasks.incremental.InputFileDetails>)
.removed(org.gradle.api.Action<? super org.gradle.api.tasks.incremental.InputFileDetails>)
.void outOfDate(Action<? super InputFileDetails> outOfDateAction)
Closure
.
isIncremental()
== true
, the action will be executed for any added or modified input file.isIncremental()
== false
, the action will be executed for every input file for the task.
This method may only be called a single time for a single IncrementalTaskInputs
instance.
IllegalStateException
- on second and subsequent invocations.void removed(Action<? super InputFileDetails> removedAction)
Closure
.
isIncremental()
== true
, the action will be executed for any removed input file.isIncremental()
== false
, the action will not be executed.
This method may only be called a single time for a single IncrementalTaskInputs
instance.
This method may only be called after outOfDate(org.gradle.api.Action<? super org.gradle.api.tasks.incremental.InputFileDetails>)
has been called.
IllegalStateException
- if invoked prior to outOfDate(org.gradle.api.Action<? super org.gradle.api.tasks.incremental.InputFileDetails>)
, or if invoked more than once.