api / org.gradle.kotlin.dsl / org.gradle.api.NamedDomainObjectCollection / getByName

getByName

inline fun <reified T : Any> NamedDomainObjectCollection<out Any>.getByName(name: String): T

Locates an object by name and casts it to the expected type T.

If an object with the given name is not found, UnknownDomainObjectException is thrown. If the object is found but cannot be cast to the expected type T, IllegalArgumentException is thrown.

Parameters

name - object name

Exceptions

UnknownDomainObjectException - When the given object is not found.

IllegalArgumentException - When the given object cannot be cast to the expected type.

Return
the object, never null

fun <T : Any> NamedDomainObjectCollection<out Any>.getByName(name: String, type: KClass<T>): T

Locates an object by name and casts it to the expected type.

If an object with the given name is not found, UnknownDomainObjectException is thrown. If the object is found but cannot be cast to the expected type, IllegalArgumentException is thrown.

Parameters

name - object name

type - expected type

Exceptions

UnknownDomainObjectException - When the given object is not found.

IllegalArgumentException - When the given object cannot be cast to the expected type.

Return
the object, never null

inline fun <reified T : Any> NamedDomainObjectCollection<out Any>.getByName(name: String, configure: T.() -> Unit): T

Locates an object by name and casts it to the expected type T then configures it.

If an object with the given name is not found, UnknownDomainObjectException is thrown. If the object is found but cannot be cast to the expected type T, IllegalArgumentException is thrown.

Parameters

name - object name

configure - configuration action to apply to the object before returning it

Exceptions

UnknownDomainObjectException - When the given object is not found.

IllegalArgumentException - When the given object cannot be cast to the expected type.

Return
the object, never null