api / org.gradle.tooling / ModelBuilder

ModelBuilder

interface ModelBuilder<T : Any> : ConfigurableLauncher<ModelBuilder<T>>

A ModelBuilder allows you to fetch a snapshot of some model for a project or a build. Instances of ModelBuilder are not thread-safe.

You use a ModelBuilder as follows:

Example:
 ProjectConnection connection = GradleConnector.newConnector() .forProjectDirectory(new File("someFolder")) .connect(); try { ModelBuilder<GradleProject> builder = connection.model(GradleProject.class); //if you use a different than usual build file name: builder.withArguments("--build-file", "theBuild.gradle"); //configure the standard input in case your build is interactive: builder.setStandardInput(new ByteArrayInputStream("consume this!".getBytes())); //if you want to listen to the progress events: ProgressListener listener = null; // use your implementation builder.addProgressListener(listener); //get the model: GradleProject project = builder.get(); //query the model for information: System.out.println("Available tasks: " + project.getTasks()); } finally { connection.close(); } 

Parameters

- The type of model to build

Since
1.0-milestone-3

Functions

forTasks

abstract fun forTasks(vararg tasks: String): ModelBuilder<T>
abstract fun forTasks(tasks: MutableIterable<String>): ModelBuilder<T>

Specifies the tasks to execute before building the model. If not configured, null, or an empty array is passed, then no tasks will be executed.

get

abstract fun get(): T

Fetch the model, blocking until it is available.

abstract fun get(handler: ResultHandler<in T>): Unit

Starts fetching the model, passing the result to the given handler when complete. This method returns immediately, and the result is later passed to the given handler's ResultHandler#onComplete(Object) method.

If the operation fails, the handler's ResultHandler#onFailure(GradleConnectionException) method is called with the appropriate exception. See #get() for a description of the various exceptions that the operation may fail with.

Inherited Functions

addProgressListener

abstract fun addProgressListener(listener: ProgressListener): T
abstract fun addProgressListener(listener: ProgressListener): T
abstract fun addProgressListener(listener: ProgressListener, eventTypes: MutableSet<OperationType>): T
abstract fun addProgressListener(listener: ProgressListener, vararg operationTypes: OperationType): T

{@inheritDoc}

setColorOutput

abstract fun setColorOutput(colorOutput: Boolean): T

{@inheritDoc}

setEnvironmentVariables

abstract fun setEnvironmentVariables(envVariables: MutableMap<String, String>): T

{@inheritDoc}

setJavaHome

abstract fun setJavaHome(javaHome: File): T

{@inheritDoc}

setJvmArguments

abstract fun setJvmArguments(vararg jvmArguments: String): T
abstract fun setJvmArguments(jvmArguments: MutableIterable<String>): T

{@inheritDoc}

setStandardError

abstract fun setStandardError(outputStream: OutputStream): T

{@inheritDoc}

setStandardInput

abstract fun setStandardInput(inputStream: InputStream): T

{@inheritDoc}

setStandardOutput

abstract fun setStandardOutput(outputStream: OutputStream): T

{@inheritDoc}

withArguments

abstract fun withArguments(vararg arguments: String): T
abstract fun withArguments(arguments: MutableIterable<String>): T

{@inheritDoc}

withCancellationToken

abstract fun withCancellationToken(cancellationToken: CancellationToken): T

{@inheritDoc}