Package: org.gradle.tooling

## [Java] Interface BuildLauncher

- org.gradle.tooling.BuildLauncher

- All Superinterfaces:
    ConfigurableLauncher, LongRunningOperation

  A `BuildLauncher` allows you to configure and execute a Gradle build.

  Instances of `BuildLauncher` are not thread-safe. You use a `BuildLauncher` as follows:

  - Create an instance of `BuildLauncher` by calling ProjectConnection.newBuild.
  - Configure the launcher as appropriate.
  - Call either run() or run(ResultHandler) to execute the build.
  - Optionally, you can reuse the launcher to launch additional builds.
  Example:

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

       try {
          BuildLauncher build = connection.newBuild();

          //select tasks to run:
          build.forTasks("clean", "test");

          //include some build arguments:
          build.withArguments("--no-search-upward", "-i", "--project-dir", "someProjectDir");

          //configure the standard input:
          build.setStandardInput(new ByteArrayInputStream("consume this!".getBytes()));

          //in case you want the build to use java different than default:
          build.setJavaHome(new File("/path/to/java"));

          //if your build needs crazy amounts of memory:
          build.setJvmArguments("-Xmx2048m", "-XX:MaxPermSize=512m");

          //if you want to listen to the progress events:
          ProgressListener listener = null; // use your implementation
          build.addProgressListener(listener);

          //kick the build off:
          build.run();
       } finally {
          connection.close();
       }

  Since:
    1.0-milestone-3

- - ### Methods Summary

    Methods
    Type | Name and description
    --- | ---
    `BuildLauncher` | `forLaunchables(Launchable... launchables)` Sets the launchables to execute.
    `BuildLauncher` | `forLaunchables(Iterable<? extends Launchable> launchables)` Sets the launchables to execute.
    `BuildLauncher` | `forTasks(String... tasks)` Sets the tasks to be executed.
    `BuildLauncher` | `forTasks(Task... tasks)` Sets the tasks to be executed.
    `BuildLauncher` | `forTasks(Iterable<? extends Task> tasks)` Sets the tasks to be executed.
    `void` | `run()` Executes the build, blocking until it is complete.
    `void` | `run(ResultHandler<? super Void> handler)` Launches the build.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `interface ConfigurableLauncher` | `addProgressListener, addProgressListener, addProgressListener, addProgressListener, setColorOutput, setJavaHome, setJvmArguments, setJvmArguments, setStandardError, setStandardInput, setStandardOutput, withArguments, withArguments, withCancellationToken`
    `interface LongRunningOperation` | `addProgressListener, addProgressListener, addProgressListener, addProgressListener, setColorOutput, setJavaHome, setJvmArguments, setJvmArguments, setStandardError, setStandardInput, setStandardOutput, withArguments, withArguments, withCancellationToken`

- - ### Method Detail

    - #### @Incubating public BuildLauncher forLaunchables(Launchable... launchables)

      Sets the launchables to execute. If no entries are specified, the project's default tasks are executed.

      Parameters:
        `launchables` - The launchables for this build.
      Returns:
        this
      Since:
        1.12

    - #### @Incubating public BuildLauncher forLaunchables(Iterable<? extends Launchable> launchables)

      Sets the launchables to execute. If no entries are specified, the project's default tasks are executed.

      Parameters:
        `launchables` - The launchables for this build.
      Returns:
        this
      Since:
        1.12

    - #### public BuildLauncher forTasks(String... tasks)

      Sets the tasks to be executed. If no tasks are specified, the project's default tasks are executed.

      Parameters:
        `tasks` - The paths of the tasks to be executed. Relative paths are evaluated relative to the project for which this launcher was created.
      Returns:
        this
      Since:
        1.0-milestone-3

    - #### public BuildLauncher forTasks(Task... tasks)

      Sets the tasks to be executed. If no tasks are specified, the project's default tasks are executed.

      Note that the supplied tasks do not necessarily need to belong to the project which this launcher was created for.

      Parameters:
        `tasks` - The tasks to be executed.
      Returns:
        this
      Since:
        1.0-milestone-3

    - #### public BuildLauncher forTasks(Iterable<? extends Task> tasks)

      Sets the tasks to be executed. If no tasks are specified, the project's default tasks are executed.

      Note that the supplied tasks do not necessarily need to belong to the project which this launcher was created for.

      Parameters:
        `tasks` - The tasks to be executed.
      Returns:
        this
      Since:
        1.0-milestone-3

    - #### public void run()

      Executes the build, blocking until it is complete.

      throws:
        UnsupportedVersionException When the target Gradle version does not support build execution.
      throws:
        org.gradle.tooling.exceptions.UnsupportedOperationConfigurationException When the target Gradle version does not support some requested configuration option such as withArguments(String...).
      throws:
        org.gradle.tooling.exceptions.UnsupportedBuildArgumentException When there is a problem with build arguments provided by withArguments(String...).
      throws:
        BuildException On some failure executing the Gradle build.
      throws:
        BuildCancelledException When the operation was cancelled before it completed successfully.
      throws:
        GradleConnectionException On some other failure using the connection.
      throws:
        IllegalStateException When the connection has been closed or is closing.
      Since:
        1.0-milestone-3

    - #### public void run(ResultHandler<? super Void> handler)

      Launches the build. This method returns immediately, and the result is later passed to the given handler.

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

      throws:
        IllegalStateException When the connection has been closed or is closing.
      Parameters:
        `handler` - The handler to supply the result to.
      Since:
        1.0-milestone-3