gradle
8.6

# ModelBuilder

interface ModelBuilder<T> : ConfigurableLauncher<T> (source)

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:

- Create an instance of `ModelBuilder` by calling model.
- Configure the builder as appropriate.
- Call either get or get to build the model.
- Optionally, you can reuse the builder to build the model multiple times.

Example:

    ProjectConnection connection = GradleConnector.newConnector()
       .forProjectDirectory(new File("someFolder"))
       .connect();

    try {
       ModelBuilder<GradleProject> builder = connection.model(GradleProject.class);

       //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();
    }

Content copied to clipboard

#### Parameters

<T>

The type of model to build

## Functions

addArguments
Link copied to clipboard
abstract fun addArguments(p: Array<String>): T
abstract fun addArguments(p: Array<String>): LongRunningOperation
addJvmArguments
Link copied to clipboard
abstract fun addJvmArguments(p: Array<String>): T
abstract fun addJvmArguments(p: Array<String>): LongRunningOperation
addProgressListener
Link copied to clipboard
abstract fun addProgressListener(p: ProgressListener): T
abstract fun addProgressListener(p: ProgressListener): LongRunningOperation
forTasks
Link copied to clipboard
abstract fun forTasks(tasks: Iterable<String>): ModelBuilder<T>
abstract fun forTasks(tasks: Array<String>): ModelBuilder<T>
Specifies the tasks to execute before building the model.
get
Link copied to clipboard
abstract fun get(): T
Fetch the model, blocking until it is available.
abstract fun get(handler: ResultHandler<out Any>)
Starts fetching the model, passing the result to the given handler when complete.
setColorOutput
Link copied to clipboard
abstract fun setColorOutput(p: Boolean): T
abstract fun setColorOutput(p: Boolean): LongRunningOperation
setEnvironmentVariables
Link copied to clipboard
abstract fun setEnvironmentVariables(p: Map<String, String>): T
abstract fun setEnvironmentVariables(p: Map<String, String>): LongRunningOperation
setJavaHome
Link copied to clipboard
abstract fun setJavaHome(p: File): T
abstract fun setJavaHome(p: File): LongRunningOperation
setJvmArguments
Link copied to clipboard
abstract fun setJvmArguments(p: Array<String>): T
abstract fun setJvmArguments(p: Array<String>): LongRunningOperation
setStandardError
Link copied to clipboard
abstract fun setStandardError(p: OutputStream): T
abstract fun setStandardError(p: OutputStream): LongRunningOperation
setStandardInput
Link copied to clipboard
abstract fun setStandardInput(p: InputStream): T
abstract fun setStandardInput(p: InputStream): LongRunningOperation
setStandardOutput
Link copied to clipboard
abstract fun setStandardOutput(p: OutputStream): T
abstract fun setStandardOutput(p: OutputStream): LongRunningOperation
withArguments
Link copied to clipboard
abstract fun withArguments(p: Array<String>): T
abstract fun withArguments(p: Array<String>): LongRunningOperation
withCancellationToken
Link copied to clipboard
abstract fun withCancellationToken(p: CancellationToken): T
abstract fun withCancellationToken(p: CancellationToken): LongRunningOperation
withSystemProperties
Link copied to clipboard
abstract fun withSystemProperties(p: Map<String, String>): T
abstract fun withSystemProperties(p: Map<String, String>): LongRunningOperation