api / org.gradle.api.file / DirectoryProperty

DirectoryProperty

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

Since
4.3

Functions

dir

abstract fun dir(path: String): Provider<Directory>
abstract fun dir(path: Provider<out CharSequence>): Provider<Directory>

Returns a Directory whose value is the given path resolved relative to the value of this directory.

file

abstract fun file(path: String): Provider<RegularFile>
abstract fun file(path: Provider<out CharSequence>): Provider<RegularFile>

Returns a RegularFile whose value is the given path resolved relative to the value of this directory.

getAsFile

abstract fun getAsFile(): Provider<File>

Views the location of this directory as a File.

getAsFileTree

abstract fun getAsFileTree(): FileTree

Returns a FileTree that allows the files and directories contained in this directory to be queried.

set

abstract fun set(dir: File): Unit

Sets the location of this directory.

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.

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.

Inheritors

DirectoryVar

interface DirectoryVar : DirectoryProperty, PropertyState<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#newDirectoryVar() method.