T
- Type of value represented by the propertyHasConfigurableValue
, Provider<T>
DirectoryProperty
, FileSystemLocationProperty<T>
, RegularFileProperty
@SupportsKotlinAssignmentOverloading public interface Property<T> extends Provider<T>, HasConfigurableValue
Property
is also a
Provider
and can be used in the same way as a Provider
. A property's value can be accessed
using the methods of Provider
such as get()
. The value can be modified by
using the methods set(Object)
and set(Provider)
, or their fluid API counterparts
value(Object)
and value(Provider)
.
A property may represent a task output. Such a property carries information about the task producing its value. When this property is attached to an input of another task, Gradle will automatically determine the task dependencies based on this connection.
You can create a Property
instance using ObjectFactory.property(Class)
. There are
also several specialized subtypes of this interface that can be created using various other factory methods.
Note: This interface is not intended for implementation by build script or plugin authors.
Modifier and Type | Method | Description |
---|---|---|
Property<T> |
convention(Provider<? extends T> provider) |
Specifies the provider to be used to query the convention (default value) for this property.
|
Property<T> |
convention(T value) |
Specifies the value to use as the convention (default value) for this property.
|
void |
finalizeValue() |
Disallows further changes to the value of this property.
|
void |
set(Provider<? extends T> provider) |
Sets the property to have the same value as the given provider, replacing whatever value the property already had.
|
void |
set(T value) |
Sets the value of the property to the given value, replacing whatever value the property already had.
|
Property<T> |
value(Provider<? extends T> provider) |
Sets the property to have the same value as the given provider, replacing whatever value the property already had.
|
Property<T> |
value(T value) |
Sets the value of the property to the given value, replacing whatever value the property already had.
|
disallowChanges, disallowUnsafeRead, finalizeValueOnRead
void set(@Nullable T value)
This method can also be used to discard the value of the property, by passing it null
. When the
value is discarded (or has never been set in the first place), the convention (default value) for this
property, if specified, will be used to provide the value instead.
value
- The value, can be null.void set(Provider<? extends T> provider)
This method can NOT be used to discard the value of the property. Specifying a null
provider will result
in an IllegalArgumentException
being thrown. When the provider has no value, this property will also have
no value - regardless of whether or not a convention has been set.
When the given provider represents a task output, this property will also carry the task dependency information from the provider.
provider
- The provider of the property's value, can't be null.Property<T> value(@Nullable T value)
set(Object)
but returns this property to allow method chaining.
This method can also be used to discard the value of the property, by passing it null
.
When the value is discarded (or has never been set in the first place), the convention (default value)
for this property, if specified, will be used to provide the value instead.
value
- The value, can be null.Property<T> value(Provider<? extends T> provider)
set(Provider)
but returns this property to allow method chaining.
This method can NOT be used to discard the value of the property. Specifying a null
provider will result
in an IllegalArgumentException
being thrown. When the provider has no value, this property will also have
no value - regardless of whether or not a convention has been set.
When the given provider represents a task output, this property will also carry the task dependency information from the provider.
provider
- The provider whose value to use.Property<T> convention(@Nullable T value)
This method can be used to specify that the property does not have a default value, by passing it
null
.
value
- The convention value, or null
if the property should have no default value.Property<T> convention(Provider<? extends T> provider)
The property's convention tracks the convention provider. Whenever the convention's actual value is needed, the convention provider will be queried anew.
This method can't be used to specify that a property does not have a default value. Passing in a null
provider will result in an IllegalArgumentException
being thrown. When the provider doesn't have
a value, then the property will behave as if it wouldn't have a convention specified.
provider
- The provider of the property's convention value, can't be null.void finalizeValue()
set(Object)
, set(Provider)
, value(Object)
and value(Provider)
will fail,
by throwing an IllegalStateException
.
When this property's value is specified via a Provider
, calling finalizeValue()
will trigger the
querying of the provider and the obtained value will be set as the final value of the property. The value of the
provider will not be tracked further.
Note that although the value of the property will not change, the value itself may be a mutable object. Calling this method does not guarantee that the value will become immutable.
finalizeValue
in interface HasConfigurableValue