public interface TaskOutputs
A TaskOutputs
represents the outputs of a task.
You can obtain a TaskOutputs
instance using Task.getOutputs()
.
Modifier and Type | Method | Description |
---|---|---|
void |
cacheIf(String cachingEnabledReason,
Spec<? super Task> spec) |
Cache the results of the task only if the given spec is satisfied.
|
void |
cacheIf(Spec<? super Task> spec) |
Cache the results of the task only if the given spec is satisfied.
|
TaskOutputFilePropertyBuilder |
dir(Object path) |
Registers an output directory for this task.
|
TaskOutputFilePropertyBuilder |
dirs(Object... paths) |
Registers some output directories for this task.
|
void |
doNotCacheIf(String cachingDisabledReason,
Spec<? super Task> spec) |
Disable caching the results of the task if the given spec is satisfied.
|
TaskOutputFilePropertyBuilder |
file(Object path) |
Registers some output file for this task.
|
TaskOutputFilePropertyBuilder |
files(Object... paths) |
Registers some output files for this task.
|
FileCollection |
getFiles() |
Returns the output files of this task.
|
boolean |
getHasOutput() |
Returns true if this task has declared any outputs.
|
void |
upToDateWhen(Closure upToDateClosure) |
Adds a predicate to determine whether previous outputs of this task can be reused.
|
void |
upToDateWhen(Spec<? super Task> upToDateSpec) |
Adds a predicate to determine whether previous outputs of this task can be reused.
|
void upToDateWhen(Closure upToDateClosure)
Adds a predicate to determine whether previous outputs of this task can be reused. The given closure is executed at task execution time. The closure is passed the task as a parameter. If the closure returns false, previous outputs of this task cannot be reused and the task will be executed. That means the task is out-of-date and no outputs will be loaded from the build cache.
You can add multiple such predicates. The task outputs cannot be reused when any predicate returns false.
upToDateClosure
- The closure to use to determine whether the task outputs are up-to-date.void upToDateWhen(Spec<? super Task> upToDateSpec)
Adds a predicate to determine whether previous outputs of this task can be reused. The given spec is evaluated at task execution time. If the spec returns false, previous outputs of this task cannot be reused and the task will be executed. That means the task is out-of-date and no outputs will be loaded from the build cache.
You can add multiple such predicates. The task outputs cannot be reused when any predicate returns false.
upToDateSpec
- The spec to use to determine whether the task outputs are up-to-date.void cacheIf(Spec<? super Task> spec)
Cache the results of the task only if the given spec is satisfied. If the spec is not satisfied, the results of the task will not be cached.
You may add multiple such predicates. The results of the task are not cached if any of the predicates return false
,
or if any of the predicates passed to doNotCacheIf(String, Spec)
returns true
. If cacheIf()
is not specified,
the task will not be cached unless the @CacheableTask
annotation is present on the task type.
Consider using cacheIf(String, Spec)
instead for also providing a reason for enabling caching.
spec
- specifies if the results of the task should be cached.void cacheIf(String cachingEnabledReason, Spec<? super Task> spec)
Cache the results of the task only if the given spec is satisfied. If the spec is not satisfied, the results of the task will not be cached.
You may add multiple such predicates. The results of the task are not cached if any of the predicates return false
,
or if any of the predicates passed to doNotCacheIf(String, Spec)
returns true
. If cacheIf()
is not specified,
the task will not be cached unless the @CacheableTask
annotation is present on the task type.
cachingEnabledReason
- the reason why caching would be enabled by the spec.spec
- specifies if the results of the task should be cached.void doNotCacheIf(String cachingDisabledReason, Spec<? super Task> spec)
Disable caching the results of the task if the given spec is satisfied. The spec will be evaluated at task execution time, not during configuration.
As opposed to cacheIf(String, Spec)
, this method never enables caching for a task, it can only be used to disable caching.
You may add multiple such predicates. The results of the task are not cached if any of the predicates return true
,
or if any of the predicates passed to cacheIf(String, Spec)
returns false
.
cachingDisabledReason
- the reason why caching would be disabled by the spec.spec
- specifies if the results of the task should not be cached.boolean getHasOutput()
FileCollection getFiles()
TaskOutputFilePropertyBuilder files(Object... paths)
When the given paths
is a Map
, then each output file
will be associated with an identity. For cacheable tasks this is a requirement.
The keys of the map must be non-empty strings.
The values of the map will be evaluated to individual files as per
Project.file(Object)
.
Otherwise the given files will be evaluated as per Project.files(Object...)
,
and task output caching will be disabled for the task.
paths
- The output files.CacheableTask
TaskOutputFilePropertyBuilder dirs(Object... paths)
When the given paths
is a Map
, then each output directory
will be associated with an identity. For cacheable tasks this is a requirement.
The keys of the map must be non-empty strings.
The values of the map will be evaluated to individual directories as per
Project.file(Object)
.
Otherwise the given directories will be evaluated as per Project.files(Object...)
,
and task output caching will be disabled for the task.
paths
- The output files.CacheableTask
TaskOutputFilePropertyBuilder file(Object path)
path
- The output file. The given path is evaluated as per Project.file(Object)
.TaskOutputFilePropertyBuilder dir(Object path)
path
- The output directory. The given path is evaluated as per Project.file(Object)
.