api / org.gradle.api.plugins / ExtensionContainer / create

create

@Incubating abstract fun <T : Any> create(publicType: Class<T>, name: String, instanceType: Class<out T>, vararg constructionArguments: Any): T
@Incubating abstract fun <T : Any> create(publicType: TypeOf<T>, name: String, instanceType: Class<out T>, vararg constructionArguments: Any): T

Creates and adds a new extension to this container. A new instance of the given instanceType will be created using the given constructionArguments. The extension will be exposed as publicType. The new instance will have been dynamically made ExtensionAware, which means that you can cast it to ExtensionAware.

Parameters

- the extension public type

publicType - The extension public type

name - The name for the extension

instanceType - The extension instance type

constructionArguments - The arguments to be used to construct the extension instance

Exceptions

IllegalArgumentException - When an extension with the given name already exists.

Return
The created instance

See Also
#add(Class, String, Object)

Since
3.5

abstract fun <T : Any> create(name: String, type: Class<T>, vararg constructionArguments: Any): T

Creates and adds a new extension to this container. A new instance of the given type will be created using the given constructionArguments. The extension will be exposed as type unless the extension itself declares a preferred public type via the org.gradle.api.reflect.HasPublicType protocol. The new instance will have been dynamically made ExtensionAware, which means that you can cast it to ExtensionAware.

Parameters

name - The name for the extension

type - The type of the extension

constructionArguments - The arguments to be used to construct the extension instance

Exceptions

IllegalArgumentException - When an extension with the given name already exists.

Return
The created instance

See Also
#add(String, Object)