Provider
A container object that provides a value of a specific type. The value can be retrieved using one of the query methods such as get or getOrNull.
A provider may not always have a value available, for example when the value may not yet be known but will be known at some point in the future. When a value is not available, isPresent returns false
and retrieving the value will fail with an exception.
A provider may not always provide the same value. Although there are no methods on this interface to change the value, the provider implementation may be mutable or use values from some changing source. A provider may also provide a value that is mutable and that changes over time.
A provider may represent a task output. Such a provider carries information about the task producing its value. When this provider is attached to an input of another task, Gradle will automatically determine the task dependencies based on this connection.
A typical use of a provider is to pass values from one Gradle model element to another, e.g. from a project extension to a task, or between tasks. Providers also allow expensive computations to be deferred until their value is actually needed, usually at task execution time.
There are a number of ways to create a Provider instance. Some common methods:
- A number of Gradle types, such as Property, extend Provider and can be used directly as a provider.
- Calling map to create a new provider from an existing provider.
- Using the return value of register, which is a provider that represents the task instance.
- Using the methods on org.gradle.api.file.Directory and org.gradle.api.file.DirectoryProperty to produce file providers.
- By calling provider or provider to create a new provider from a Callable.
For a provider whose value can be mutated, see Property and the methods on org.gradle.api.model.ObjectFactory.
Note: This interface is not intended for implementation by build script or plugin authors.
Since
4.0
Parameters
Type of value represented by provider