api / org.gradle.api.model / ObjectFactory / newInstance

newInstance

abstract fun <T : Any> newInstance(type: Class<out T>, vararg parameters: Any): T

Create a new instance of T, using parameters as the construction parameters.

The type must be a non-abstract class.

Objects created using this method are decorated and extensible, meaning that they have DSL support mixed in and can be extended using the `extensions` property, similar to the org.gradle.api.Project object.

An @Inject annotation is required on any constructor that accepts parameters because JSR-330 semantics for dependency injection are used. In addition to those parameters provided as an argument to this method, the following services are also available for injection:

Exceptions

ObjectInstantiationException - On failure to create the new instance.

Since
4.2