# Convention

interface Convention : ExtensionContainer

### Deprecated

A `Convention` manages a set of convention objects. When you add a convention object to a `Convention`, and the properties and methods of the convention object become available as properties and methods of the object which the convention is associated to. A convention object is simply a POJO or POGO. Usually, a `Convention` is used by plugins to extend a org.gradle.api.Project or a org.gradle.api.Task.

#### Deprecated

Use extensions instead. This is scheduled for removal in Gradle 9.

#### See also

ExtensionAware

## Functions

add
Link copied to clipboard
abstract fun <T> add(publicType: Class<T>, name: String, extension: T)
add
Link copied to clipboard
inline fun <T : Any> ExtensionContainer. add(name: String, extension: T)

Adds a new extension to this container.

inline fun <T : Any> ExtensionContainer. add(publicType: KClass<T>, name: String, extension: T)

Kotlin extension function taking kotlin.reflect.KClass for org.gradle.api.plugins.ExtensionContainer.add.

configure
Link copied to clipboard
abstract fun <T> configure(type: Class<T>, action: Action<in T>)
configure
Link copied to clipboard
inline fun <T : Any> ExtensionContainer. configure(noinline action: T.() -> Unit)

Looks for the extension of the specified type and configures it with the supplied action.

inline fun <T : Any> ExtensionContainer. configure(type: KClass<T>, action: Action<in T>)

Kotlin extension function taking kotlin.reflect.KClass for org.gradle.api.plugins.ExtensionContainer.configure.

create
Link copied to clipboard
abstract fun <T> create(publicType: Class<T>, name: String, instanceType: Class<out T>, constructionArguments: Array<Any>): T
create
Link copied to clipboard
inline fun <T : Any> ExtensionContainer. create(name: String, vararg constructionArguments: Any): T

Creates and adds a new extension to this container.

inline fun <T : Any> ExtensionContainer. create(name: String, type: KClass<T>, vararg constructionArguments: Any): T
inline fun <T : Any> ExtensionContainer. create(publicType: KClass<T>, name: String, instanceType: KClass<out T>, vararg constructionArguments: Any): T
inline fun <T : Any> ExtensionContainer. create(publicType: TypeOf<T>, name: String, instanceType: KClass<out T>, vararg constructionArguments: Any): T

Kotlin extension function taking kotlin.reflect.KClass for org.gradle.api.plugins.ExtensionContainer.create.

findByName
Link copied to clipboard
abstract fun findByName(name: String): Any
findByType
Link copied to clipboard
abstract fun <T> findByType(type: Class<T>): T
findByType
Link copied to clipboard
inline fun <T : Any> ExtensionContainer. findByType(): T?

Looks for the extension of a given type.

inline fun <T : Any> ExtensionContainer. findByType(type: KClass<T>): T?

Kotlin extension function taking kotlin.reflect.KClass for org.gradle.api.plugins.ExtensionContainer.findByType.

findPlugin
Link copied to clipboard
@Nullable
abstract fun <T> findPlugin(type: Class<T>): T
Locates the plugin convention object with the given type.
findPlugin
Link copied to clipboard
inline fun <T : Any> Convention. findPlugin(): T?
fun <T : Any> Convention. findPlugin(conventionType: KClass<T>): T?

Locates the plugin convention object with the given type.

get
Link copied to clipboard
operator fun ExtensionContainer. get(name: String): Any

Looks for the extension of a given name. If none found it will throw an exception.

getByName
Link copied to clipboard
abstract fun getByName(name: String): Any
getByName
Link copied to clipboard
inline fun <T : Any> ExtensionContainer. getByName(name: String): T

Looks for the extension of a given name and casts it to the expected type T.

getByType
Link copied to clipboard
abstract fun <T> getByType(type: Class<T>): T
getByType
Link copied to clipboard
inline fun <T : Any> ExtensionContainer. getByType(): T

Looks for the extension of a given type.

inline fun <T : Any> ExtensionContainer. getByType(type: KClass<T>): T

Kotlin extension function taking kotlin.reflect.KClass for org.gradle.api.plugins.ExtensionContainer.getByType.

getExtensionsAsDynamicObject
Link copied to clipboard
abstract fun getExtensionsAsDynamicObject(): DynamicObject
Returns a dynamic object which represents the properties and methods contributed by the extensions and convention objects contained in this convention.
getExtensionsSchema
Link copied to clipboard
abstract fun getExtensionsSchema(): ExtensionsSchema
getExtraProperties
Link copied to clipboard
abstract fun getExtraProperties(): ExtraPropertiesExtension
getPlugin
Link copied to clipboard
abstract fun <T> getPlugin(type: Class<T>): T
Locates the plugin convention object with the given type.
getPlugin
Link copied to clipboard
inline fun <T : Any> Convention. getPlugin(): T
fun <T : Any> Convention. getPlugin(conventionType: KClass<T>): T

Locates the plugin convention object with the given type.

getPluginByName
Link copied to clipboard
inline fun <T : Any> Convention. getPluginByName(name: String): T

Looks for the convention plugin of a given name and casts it to the expected type T.

getPlugins
Link copied to clipboard
abstract fun getPlugins(): Map<String, Any>
Returns the plugin convention objects contained in this convention.
getValue
Link copied to clipboard
inline operator fun <T : Any> ExtensionContainer. getValue(thisRef: Any?, property: KProperty<*>): T

Delegated property getter that locates extensions.