# Interface LongRunningOperation

All Known Subinterfaces:
  `BuildActionExecuter<T>, BuildLauncher, ConfigurableLauncher<T>, ModelBuilder<T>, TestLauncher`

public 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

- ## Method Summary

  Modifier and Type
  Method
  Description
  `LongRunningOperation`
  `addArguments(Iterable<String> arguments)`
  Appends new command line arguments to the existing list.
  `LongRunningOperation`
  `addArguments(String... arguments)`
  Appends new command line arguments to the existing list.
  `LongRunningOperation`
  `addJvmArguments(Iterable<String> jvmArguments)`
  Appends Java VM arguments to the existing list.
  `LongRunningOperation`
  `addJvmArguments(String... jvmArguments)`
  Appends Java VM arguments to the existing list.
  `LongRunningOperation`
  `addProgressListener(ProgressListener listener)`
  Adds a progress listener which will receive progress events of all types as the operation runs.
  `LongRunningOperation`
  `addProgressListener(ProgressListener listener, Set<OperationType> operationTypes)`
  Adds a progress listener which will receive progress events as the operations of the requested type run.
  `LongRunningOperation`
  `addProgressListener(ProgressListener listener, OperationType... operationTypes)`
  Adds a progress listener which will receive progress events as the operations of the requested type run.
  `LongRunningOperation`
  `addProgressListener(ProgressListener listener)`
  Adds a progress listener which will receive progress events as the operation runs.
  `LongRunningOperation`
  `setColorOutput(boolean colorOutput)`
  Specifies whether to generate colored (ANSI encoded) output for logging.
  `LongRunningOperation`
  `setEnvironmentVariables(@Nullable Map<String,String> envVariables)`
  Specifies the environment variables to use for this operation.
  `LongRunningOperation`
  `setJavaHome(@Nullable File javaHome)`
  Specifies the Java home directory to use for this operation.
  `LongRunningOperation`
  `setJvmArguments(@Nullable Iterable<String> jvmArguments)`
  Specifies the Java VM arguments to use for this operation.
  `LongRunningOperation`
  `setJvmArguments(@Nullable String... jvmArguments)`
  Specifies the Java VM arguments to use for this operation.
  `LongRunningOperation`
  `setStandardError(OutputStream outputStream)`
  Sets the `OutputStream` which should receive standard error logging generated while running the operation.
  `LongRunningOperation`
  `setStandardInput(InputStream inputStream)`
  Sets the `InputStream` that will be used as standard input for this operation.
  `LongRunningOperation`
  `setStandardOutput(OutputStream outputStream)`
  Sets the `OutputStream` which should receive standard output logging generated while running the operation.
  `LongRunningOperation`
  `withArguments(@Nullable Iterable<String> arguments)`
  Specify the command line build arguments.
  `LongRunningOperation`
  `withArguments(@Nullable String... arguments)`
  Specify the command line build arguments.
  `LongRunningOperation`
  `withCancellationToken(CancellationToken cancellationToken)`
  Sets the cancellation token to use to cancel the operation if required.
  `LongRunningOperation`
  `withDetailedFailure()`
  Adds more detailed information about the build failure to the `GradleConnectionException` that provides insights into the reasons for the failure, making it easier to diagnose and fix issues.
  `LongRunningOperation`
  `withSystemProperties(Map<String,String> systemProperties)`
  Sets system properties to pass to the build.

- ## Method Details

  - ### setStandardOutput

    LongRunningOperation setStandardOutput(OutputStream outputStream)
    Sets the `OutputStream` which should receive standard output logging generated while running the operation. The default is to discard the output.
    Parameters:
      `outputStream` - The output stream. The system default character encoding will be used to encode characters written to this stream.
    Returns:
      this
    Since:
      1.0-milestone-7

  - ### setStandardError

    LongRunningOperation setStandardError(OutputStream outputStream)
    Sets the `OutputStream` which should receive standard error logging generated while running the operation. The default is to discard the output.
    Parameters:
      `outputStream` - The output stream. The system default character encoding will be used to encode characters written to this stream.
    Returns:
      this
    Since:
      1.0-milestone-7

  - ### setColorOutput

    LongRunningOperation setColorOutput(boolean colorOutput)
    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.

    Parameters:
      `colorOutput` - `true` to request color output (using ANSI encoding).
    Returns:
      this
    Since:
      2.3

  - ### setStandardInput

    LongRunningOperation setStandardInput(InputStream inputStream)
    Sets the `InputStream` that will be used as standard input for this operation. Defaults to an empty input stream.
    Parameters:
      `inputStream` - The input stream
    Returns:
      this
    Since:
      1.0-milestone-8

  - ### setJavaHome

    LongRunningOperation setJavaHome(@Nullable File javaHome) throws IllegalArgumentException
    Specifies the Java home directory to use for this operation.

    `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.

    Parameters:
      `javaHome` - to use for the Gradle process
    Returns:
      this
    Throws:
      `IllegalArgumentException` - when supplied javaHome is not a valid folder.
    Since:
      1.0-milestone-8

  - ### setJvmArguments

    LongRunningOperation setJvmArguments(@Nullable String... jvmArguments)
    Specifies the Java VM arguments to use for this operation.

    `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.

    The jvm argument set by this method is independent of arguments set by {`addJvmArguments`} methods. The daemon JVM arguments list will always have the arguments from the {`setJvmArguments`} at the beginning of the list, and then have the {`addJvmArguments`} configuration appended.

    Parameters:
      `jvmArguments` - to use for the Gradle process
    Returns:
      this
    Since:
      1.0-milestone-8

  - ### addJvmArguments

    LongRunningOperation addJvmArguments(String... jvmArguments)
    Appends Java VM arguments to the existing list.

    The jvm argument set by this method is independent of arguments set by {`setJvmArguments`} methods. The daemon JVM arguments list will always have the arguments from the {`setJvmArguments`} at the beginning of the list, and then have the {`addJvmArguments`} configuration appended.

    Parameters:
      `jvmArguments` - the argument to use for the Gradle process
    Returns:
      this
    Since:
      5.0

  - ### withSystemProperties

    @Incubating LongRunningOperation withSystemProperties(Map<String,String> systemProperties)
    Sets system properties to pass to the build.

    By default, the Tooling API passes all system properties defined in the client to the build. If called, this method limits the system properties that are passed to the build, except for immutable system properties that need to match on both sides.

    System properties can be also defined in the build scripts (and in the gradle.properties file), or with a JVM argument. In case of an overlapping system property definition the precedence is as follows:

    - `withSystemProperties(...)` (highest)
    - `addJvmArguments(...)` and `setJvmArguments(...)`
    - build scripts

    Note: this method has "setter" behavior, so the last invocation will overwrite previously set values.

    Parameters:
      `systemProperties` - the system properties add to the Gradle process. Passing `null` resets to the default behavior.
    Returns:
      this
    Since:
      7.6

  - ### addJvmArguments

    LongRunningOperation addJvmArguments(Iterable<String> jvmArguments)
    Appends Java VM arguments to the existing list.

    The jvm argument set by this method is independent of arguments set by {`setJvmArguments`} methods. The daemon JVM arguments list will always have the arguments from the {`setJvmArguments`} at the beginning of the list, and then have the {`addJvmArguments`} configuration appended.

    Parameters:
      `jvmArguments` - the argument to use for the Gradle process
    Returns:
      this
    Since:
      5.0

  - ### setJvmArguments

    LongRunningOperation setJvmArguments(@Nullable Iterable<String> jvmArguments)
    Specifies the Java VM arguments to use for this operation.

    `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.

    The jvm argument set by this method is independent of arguments set by {`addJvmArguments`} methods. The daemon JVM arguments list will always have the arguments from the {`setJvmArguments`} at the beginning of the list, and then have the {`addJvmArguments`} configuration appended.

    Parameters:
      `jvmArguments` - to use for the Gradle process
    Returns:
      this
    Since:
      2.6

  - ### withArguments

    LongRunningOperation withArguments(@Nullable String... arguments)
    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 `StartParameter`. Examples of supported build arguments: '--info', '-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, `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 Manual or take a look at the output of the 'gradle -?' command. Majority of arguments modeled by `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.

    Parameters:
      `arguments` - Gradle command line arguments
    Returns:
      this
    Since:
      1.0

  - ### withArguments

    LongRunningOperation withArguments(@Nullable Iterable<String> arguments)
    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.

    Parameters:
      `arguments` - Gradle command line arguments
    Returns:
      this
    Since:
      2.6

  - ### addArguments

    LongRunningOperation addArguments(String... arguments)
    Appends new command line arguments to the existing list. Useful mostly for running tasks via `BuildLauncher`.
    Parameters:
      `arguments` - Gradle command line arguments
    Returns:
      this
    Since:
      5.0

  - ### addArguments

    LongRunningOperation addArguments(Iterable<String> arguments)
    Appends new command line arguments to the existing list. Useful mostly for running tasks via `BuildLauncher`.
    Parameters:
      `arguments` - Gradle command line arguments
    Returns:
      this
    Since:
      5.0

  - ### setEnvironmentVariables

    LongRunningOperation setEnvironmentVariables(@Nullable Map<String,String> envVariables)
    Specifies the environment variables to use for this operation.

    `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. *

    Note: When this method is called, the provided map completely replaces the environment variables for the operation. To add custom environment variables while preserving system environment variables, first copy the current environment and then add custom values:

         Map<String, String> env = new HashMap<>(System.getenv());
         env.put("MY_VAR", "my_value");
         operation.setEnvironmentVariables(env);

    This is particularly important on Windows, where omitting essential system environment variables may cause the operation to fail.
    Parameters:
      `envVariables` - environment variables
    Returns:
      this
    Since:
      3.5

  - ### addProgressListener

    LongRunningOperation addProgressListener(ProgressListener listener)
    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.

    Parameters:
      `listener` - The listener
    Returns:
      this
    Since:
      1.0-milestone-7

  - ### addProgressListener

    LongRunningOperation addProgressListener(ProgressListener listener)
    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.

    Parameters:
      `listener` - The listener
    Returns:
      this
    Since:
      2.5

  - ### addProgressListener

    LongRunningOperation addProgressListener(ProgressListener listener, Set<OperationType> operationTypes)
    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.

    Parameters:
      `listener` - The listener
      `operationTypes` - The types of operations to receive progress events for.
    Returns:
      this
    Since:
      2.5

  - ### addProgressListener

    LongRunningOperation addProgressListener(ProgressListener listener, OperationType... operationTypes)
    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.

    Parameters:
      `listener` - The listener
      `operationTypes` - The types of operations to receive progress events for.
    Returns:
      this
    Since:
      2.6

  - ### withCancellationToken

    LongRunningOperation withCancellationToken(CancellationToken cancellationToken)
    Sets the cancellation token to use to cancel the operation if required.

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

    Since:
      2.1

  - ### withDetailedFailure

    @Incubating LongRunningOperation withDetailedFailure()
    Adds more detailed information about the build failure to the `GradleConnectionException` that provides insights into the reasons for the failure, making it easier to diagnose and fix issues.
    Returns:
      this
    Since:
      8.12