# Provider

@NonExtensible
interface Provider<T>(source)

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

<T>

Type of value represented by provider

#### Inheritors

BinaryProvider
NamedDomainObjectProvider
MapProperty
SetProperty
Property
ListProperty

## Functions

filter
Link copied to clipboard
@Incubating
abstract fun filter(spec: Spec<in T>): Provider<T>
Returns a new Provider with the value of this provider if the passed spec is satisfied and no value otherwise.
flatMap
Link copied to clipboard
abstract fun <S> flatMap(transformer: Transformer<out @Nullable Provider<out S>, in T>): Provider<S>
Returns a new Provider from the value of this provider transformed using the given function.
forUseAtConfigurationTime
Link copied to clipboard
abstract fun forUseAtConfigurationTime(): Provider<T>
Deprecated.
get
Link copied to clipboard
abstract fun get(): T
Returns the value of this provider if it has a value present, otherwise throws `java.lang.IllegalStateException`.
getOrElse
Link copied to clipboard
abstract fun getOrElse(defaultValue: T): T
Returns the value of this provider if it has a value present.
getOrNull
Link copied to clipboard
@Nullable
abstract fun getOrNull(): T
Returns the value of this provider if it has a value present.
isPresent
Link copied to clipboard
abstract fun isPresent(): Boolean
Returns `true` if there is a value present, otherwise `false`.
map
Link copied to clipboard
abstract fun <S> map(transformer: Transformer<out @Nullable S, in T>): Provider<S>
Returns a new Provider whose value is the value of this provider transformed using the given function.
orElse
Link copied to clipboard
abstract fun orElse(value: T): Provider<T>
Returns a Provider whose value is the value of this provider, if present, otherwise the given default value.
abstract fun orElse(provider: Provider<out T>): Provider<T>
Returns a Provider whose value is the value of this provider, if present, otherwise uses the value from the given provider, if present.
zip
Link copied to clipboard
abstract fun <U, R> zip(right: Provider<U>, combiner: BiFunction<in T, in U, out @Nullable R>): Provider<R>
Returns a provider which value will be computed by combining this provider value with another provider value using the supplied combiner function.