api / org.gradle.tooling / BuildController / getModel

getModel

abstract fun <T : Any> getModel(modelType: Class<T>): T

Fetches a snapshot of the model of the given type for the default project. The default project is generally the project referenced when a ProjectConnection is created.

Any of following models types may be available, depending on the version of Gradle being used by the target build:

A build may also expose additional custom tooling models. You can use this method to query these models.

Parameters

modelType - The model type.

- The model type.

Exceptions

UnknownModelException - When the default project does not support the requested model.

Return
The model.

Since
1.8

abstract fun <T : Any> getModel(target: Model, modelType: Class<T>): T

Fetches a snapshot of the model of the given type for the given element, usually a Gradle project.

The following elements are supported:

See #getModel(Class) for more details.

Parameters

target - The target element, usually a project.

modelType - The model type.

- The model type.

Exceptions

UnknownModelException - When the target project does not support the requested model.

Return
The model.

abstract fun <T : Any, P : Any> getModel(modelType: Class<T>, parameterType: Class<P>, parameterInitializer: Action<in P>): T

Fetches a snapshot of the model of the given type using the given parameter.

See #getModel(Model, Class, Class, Action) for more details.

Parameters

modelType - The model type.

- The model type.

parameterType - The parameter type.

- The parameter type.

parameterInitializer - Action to configure the parameter

Exceptions

UnknownModelException - When the target project does not support the requested model.

UnsupportedVersionException - When the target project does not support the requested model or Gradle version does not support parametrized models.

Return
The model.

Since
4.4

abstract fun <T : Any, P : Any> getModel(target: Model, modelType: Class<T>, parameterType: Class<P>, parameterInitializer: Action<in P>): T

Fetches a snapshot of the model of the given type for the given element using the given parameter.

The parameter type must be an interface only with getters and setters and no nesting is supported. The Tooling API will create a proxy instance of this interface and use the initializer to run against that instance to configure it and then pass to the model builder.

See #getModel(Class) for more details.

Parameters

target - The target element, usually a project.

modelType - The model type.

- The model type.

parameterType - The parameter type.

- The parameter type.

parameterInitializer - Action to configure the parameter

Exceptions

UnknownModelException - When the target project does not support the requested model.

UnsupportedVersionException - When the target project does not support the requested model or Gradle version does not support parametrized models.

Return
The model.

Since
4.4