Interface TaskOutputs

All Superinterfaces:
CompatibilityAdapterForTaskOutputs
All Known Subinterfaces:
TaskOutputFilePropertyBuilder

public interface TaskOutputs extends CompatibilityAdapterForTaskOutputs

A TaskOutputs represents the outputs of a task.

You can obtain a TaskOutputs instance using Task.getOutputs().

  • Method Details

    • upToDateWhen

      void upToDateWhen(Closure upToDateClosure)

      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.

      Parameters:
      upToDateClosure - The closure to use to determine whether the task outputs are up-to-date.
    • upToDateWhen

      void upToDateWhen(Spec<? super Task> upToDateSpec)

      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.

      Parameters:
      upToDateSpec - The spec to use to determine whether the task outputs are up-to-date.
    • cacheIf

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

      Parameters:
      spec - specifies if the results of the task should be cached.
      Since:
      3.0
    • cacheIf

      @Incubating 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.

      Parameters:
      cachingEnabledReason - the reason why caching would be enabled by the spec.
      spec - specifies if the results of the task should be cached.
      Since:
      3.4
    • doNotCacheIf

      @Incubating 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. If the spec is not satisfied, the results of the task will be cached according to cacheIf(Spec).

      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.

      Parameters:
      cachingDisabledReason - the reason why caching would be disabled by the spec.
      spec - specifies if the results of the task should not be cached.
      Since:
      3.4
    • getHasOutput

      boolean getHasOutput()
      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.
      Returns:
      true if this task has declared any outputs, otherwise false.
    • getFiles

      FileCollection getFiles()
      Returns the output files of this task.
      Returns:
      The output files. Returns an empty collection if this task has no output files.
    • files

      Registers some output files for this task.

      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 valid Java identifiers. 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.

      Specified by:
      files in interface CompatibilityAdapterForTaskOutputs
      Parameters:
      paths - The output files.
      Returns:
      this
      See Also:
    • dirs

      Registers some output directories for this task.

      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 valid Java identifiers. 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.

      Parameters:
      paths - The output files.
      Since:
      3.3
      See Also:
    • file

      Registers some output file for this task.
      Specified by:
      file in interface CompatibilityAdapterForTaskOutputs
      Parameters:
      path - The output file. The given path is evaluated as per Project.file(Object).
      Returns:
      a property builder to further configure this property.
    • dir

      Registers an output directory for this task.
      Specified by:
      dir in interface CompatibilityAdapterForTaskOutputs
      Parameters:
      path - The output directory. The given path is evaluated as per Project.file(Object).
      Returns:
      a property builder to further configure this property.