api / org.gradle.tooling / LongRunningOperation

LongRunningOperation

interface LongRunningOperation

Offers ways to communicate both ways with a Gradle operation, be it building a model or running tasks.

Enables tracking progress via listeners that will receive events from the Gradle operation.

Allows providing standard output streams that will receive output if the Gradle operation writes to standard streams.

Allows providing standard input that can be consumed by the gradle operation (useful for interactive builds).

Enables configuring the build run / model request with options like the Java home or JVM arguments. Those settings might not be supported by the target Gradle version. Refer to Javadoc for those methods to understand what kind of exception throw and when is it thrown.

Since
1.0-milestone-7

Functions

addProgressListener

abstract fun addProgressListener(listener: ProgressListener): LongRunningOperation

Adds a progress listener which will receive progress events as the operation runs.

This method is intended to be replaced by #addProgressListener(org.gradle.tooling.events.ProgressListener). The new progress listener type provides much richer information and much better handling of parallel operations that run during the build, such as tasks that run in parallel. You should prefer using the new listener interface where possible. Note, however, that the new interface is supported only for Gradle 2.5.

abstract fun addProgressListener(listener: ProgressListener): LongRunningOperation

Adds a progress listener which will receive progress events of all types as the operation runs.

This method is intended to replace #addProgressListener(ProgressListener). You should prefer using the new progress listener method where possible, as the new interface provides much richer information and much better handling of parallel operations that run during the build.

Supported by Gradle 2.5 or later. Gradle 2.4 supports OperationType#TEST operations only. Ignored for older versions.

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

Adds a progress listener which will receive progress events as the operations of the requested type run.

This method is intended to replace #addProgressListener(ProgressListener). You should prefer using the new progress listener method where possible, as the new interface provides much richer information and much better handling of parallel operations that run during the build.

Supported by Gradle 2.5 or later. Gradle 2.4 supports OperationType#TEST operations only. Ignored for older versions.

setColorOutput

abstract fun setColorOutput(colorOutput: Boolean): LongRunningOperation

Specifies whether to generate colored (ANSI encoded) output for logging. The default is to not generate color output.

Supported by Gradle 2.3 or later. Ignored for older versions.

setEnvironmentVariables

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

Specifies the environment variables to use for this operation.

org.gradle.tooling.model.build.BuildEnvironment model contains information such as Java or Gradle environment. If you want to get hold of this information you can ask tooling API to build this model.

If not configured or null is passed, then the reasonable default will be used.

setJavaHome

abstract fun setJavaHome(javaHome: File): LongRunningOperation

Specifies the Java home directory to use for this operation.

org.gradle.tooling.model.build.BuildEnvironment model contains information such as Java or Gradle environment. If you want to get hold of this information you can ask tooling API to build this model.

If not configured or null is passed, then the sensible default will be used.

setJvmArguments

abstract fun setJvmArguments(vararg jvmArguments: String): LongRunningOperation

Specifies the Java VM arguments to use for this operation.

org.gradle.tooling.model.build.BuildEnvironment model contains information such as Java or Gradle environment. If you want to get hold of this information you can ask tooling API to build this model.

If not configured, null, or an empty array is passed, then the reasonable default will be used.

abstract fun setJvmArguments(jvmArguments: MutableIterable<String>): LongRunningOperation

Specifies the Java VM arguments to use for this operation.

org.gradle.tooling.model.build.BuildEnvironment model contains information such as Java or Gradle environment. If you want to get hold of this information you can ask tooling API to build this model.

If not configured, null, or an empty list is passed, then the reasonable default will be used.

setStandardError

abstract fun setStandardError(outputStream: OutputStream): LongRunningOperation

Sets the OutputStream which should receive standard error logging generated while running the operation. The default is to discard the output.

setStandardInput

abstract fun setStandardInput(inputStream: InputStream): LongRunningOperation

Sets the java.io.InputStream that will be used as standard input for this operation. Defaults to an empty input stream.

setStandardOutput

abstract fun setStandardOutput(outputStream: OutputStream): LongRunningOperation

Sets the java.io.OutputStream which should receive standard output logging generated while running the operation. The default is to discard the output.

withArguments

abstract fun withArguments(vararg arguments: String): LongRunningOperation

Specify the command line build arguments. Useful mostly for running tasks via BuildLauncher.

Be aware that not all of the Gradle command line options are supported! Only the build arguments that configure the build execution are supported. They are modelled in the Gradle API via org.gradle.StartParameter. Examples of supported build arguments: '--info', '-u', '-p'. The command line instructions that are actually separate commands (like '-?' and '-v') are not supported. Some other instructions like '--daemon' are also not supported - the tooling API always runs with the daemon.

If an unknown or unsupported command line option is specified, org.gradle.tooling.exceptions.UnsupportedBuildArgumentException will be thrown at the time the operation is executed via BuildLauncher#run() or ModelBuilder#get().

For the list of all Gradle command line options please refer to the user guide or take a look at the output of the 'gradle -?' command. Majority of arguments modeled by org.gradle.StartParameter are supported.

The arguments can potentially override some other settings you have configured. For example, the project directory or Gradle user home directory that are configured in the GradleConnector. Also, the task names configured by BuildLauncher#forTasks(String...) can be overridden if you happen to specify other tasks via the build arguments.

See the example in the docs for BuildLauncher If not configured, null, or an empty array is passed, then the reasonable default will be used.

Requires Gradle 1.0 or later.

abstract fun withArguments(arguments: MutableIterable<String>): LongRunningOperation

Specify the command line build arguments. Useful mostly for running tasks via BuildLauncher.

If not configured, null, or an empty list is passed, then the reasonable default will be used.

Requires Gradle 1.0 or later.

withCancellationToken

abstract fun withCancellationToken(cancellationToken: CancellationToken): LongRunningOperation

Sets the cancellation token to use to cancel the operation if required.

Supported by Gradle 2.1 or later. Ignored for older versions.

Inheritors

ConfigurableLauncher

interface ConfigurableLauncher<T : ConfigurableLauncher<ConfigurableLauncher<*>>> : LongRunningOperation

A ConfigurableLauncher allows you to configure a long running operation.