api / org.gradle.api.provider / Property

Property

@Incubating interface Property<T : Any> : Provider<T>

A Provider representation for capturing the state of a property. The value can be provided by using the method #set(Object) or #set(Provider).

Note: This interface is not intended for implementation by build script or plugin authors. An instance of this class can be created through the factory method org.gradle.api.model.ObjectFactory#property(Class). There are also several specialized subtypes of this interface that can be created using various other factory methods.

Parameters

- Type of value represented by the property

Since
4.3

Functions

set

abstract fun set(value: T): Unit

Sets the value of the property the given value.

This method can also be used to clear the value of the property, by passing null as the value.

abstract fun set(provider: Provider<out T>): Unit

Sets the property to have the same value of the given provider. This property will track the value of the provider and query its value each time the value of the property is queried. When the provider has no value, this property will also have no value.

Inherited Functions

get

abstract fun get(): T

Returns the value of this provider if it has a value present, otherwise throws java.lang.IllegalStateException.

getOrElse

abstract fun getOrElse(defaultValue: T): T

Returns the value of this provider if it has a value present. Returns the given default value if a value is not available.

getOrNull

abstract fun getOrNull(): T

Returns the value of this provider if it has a value present. Returns null a value is not available.

isPresent

abstract fun isPresent(): Boolean

Returns true if there is a value present, otherwise false.

map

abstract fun <S : Any> map(transformer: Transformer<out S, in T>): Provider<S>

Returns a new Provider whose value is the value of this provider transformed using the given function.

The new provider will be live, so that each time it is queried, it queries this provider and applies the transformation to the result. Whenever this provider has no value, the new provider will also have no value.

Note that the new provider may cache the result of the transformations and so there is no guarantee that the transformer is called on every query of the new provider. The new provider will apply the transformation lazily, and calculate the value for the new provider when queried.

Extension Functions

getValue

operator fun <T> Property<T>.getValue(receiver: Any?, property: KProperty<*>): T

Property delegate for Property instances.

setValue

operator fun <T> Property<T>.setValue(receiver: Any?, property: KProperty<*>, value: T): Unit

Property delegate for Property instances.

Inheritors

DirectoryProperty

interface DirectoryProperty : Provider<Directory>, Property<Directory>

Represents some configurable directory location, whose value is mutable and is not necessarily currently known until later.

Note: This interface is not intended for implementation by build script or plugin authors. An instance of this class can be created using the ProjectLayout#directoryProperty() method.

PropertyState

interface PropertyState<T : Any> : Property<T>

A Provider representation for capturing the state of a property. The value can be provided by using the method #set(Object) or #set(Provider).

Note: This interface is not intended for implementation by build script or plugin authors. An instance of this class can be created through the factory methods org.gradle.api.Project#property(java.lang.Class) or org.gradle.api.provider.ProviderFactory#property(java.lang.Class).

RegularFileProperty

interface RegularFileProperty : Provider<RegularFile>, Property<RegularFile>

Represents some configurable regular file location, whose value is mutable and not necessarily currently known until later.

Note: This interface is not intended for implementation by build script or plugin authors. An instance of this class can be created using the ProjectLayout#fileProperty() method.