api / org.gradle.api.tasks / TaskOutputs

TaskOutputs

interface TaskOutputs : CompatibilityAdapterForTaskOutputs

A TaskOutputs represents the outputs of a task.

You can obtain a TaskOutputs instance using org.gradle.api.Task#getOutputs().

Functions

cacheIf

abstract fun cacheIf(spec: Spec<in Task>): Unit

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 disabling caching.

abstract fun cacheIf(cachingEnabledReason: String, spec: Spec<in Task>): Unit

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.

dir

abstract fun dir(path: Any): TaskOutputFilePropertyBuilder

Registers an output directory for this task.

dirs

abstract fun dirs(vararg paths: Any): TaskOutputFilePropertyBuilder

Registers some output directories for this task.

When the given paths is a java.util.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 org.gradle.api.Project#file(Object).

Otherwise the given directories will be evaluated as per org.gradle.api.Project#files(Object...), and task output caching will be disabled for the task.

doNotCacheIf

abstract fun doNotCacheIf(cachingDisabledReason: String, spec: Spec<in Task>): Unit

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.

file

abstract fun file(path: Any): TaskOutputFilePropertyBuilder

Registers some output file for this task.

files

abstract fun files(vararg paths: Any): TaskOutputFilePropertyBuilder

Registers some output files for this task.

When the given paths is a java.util.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 org.gradle.api.Project#file(Object).

Otherwise the given files will be evaluated as per org.gradle.api.Project#files(Object...), and task output caching will be disabled for the task.

getFiles

abstract fun getFiles(): FileCollection

Returns the output files of this task.

getHasOutput

abstract fun getHasOutput(): Boolean

Returns true if this task has declared any outputs. Note that a task may be able to produce output files and still have an empty set of output files.

upToDateWhen

abstract fun upToDateWhen(upToDateClosure: Closure<Any>): Unit

Adds a predicate to determine whether the outputs of this task are up-to-date. The given closure is executed at task execution time. The closure is passed the task as a parameter. If the closure returns false, the task outputs are considered out-of-date and the task will be executed.

You can add multiple such predicates. The task outputs are considered out-of-date when any predicate returns false.

abstract fun upToDateWhen(upToDateSpec: Spec<in Task>): Unit

Adds a predicate to determine whether the outputs of this task are up-to-date. The given spec is evaluated at task execution time. If the spec returns false, the task outputs are considered out-of-date and the task will be executed.

You can add multiple such predicates. The task outputs are considered out-of-date when any predicate returns false.

Inheritors

TaskOutputFilePropertyBuilder

interface TaskOutputFilePropertyBuilder : TaskFilePropertyBuilder, TaskOutputs

Describes an output property of a task that contains zero or more files.