Interface BuildLauncher

  • All Superinterfaces:
    ConfigurableLauncher<BuildLauncher>, LongRunningOperation

    public interface BuildLauncher
    extends ConfigurableLauncher<BuildLauncher>
    A BuildLauncher allows you to configure and execute a Gradle build.

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

    Example:
     ProjectConnection connection = GradleConnector.newConnector()
        .forProjectDirectory(new File("some-folder"))
        .connect();
    
     try {
        BuildLauncher build = connection.newBuild();
    
        //select tasks to run:
        build.forTasks("clean", "test");
    
        //include some build arguments:
        build.withArguments("-i", "--project-dir", "some-project-dir");
    
        //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();
     }
     

    If the target Gradle version is >=6.8 then you can use BuildLauncher to execute tasks from included builds. You can target tasks from included builds by specifying the task identity path (i.e. ':included-build-name:subproject-name:taskName').

    Since:
    1.0-milestone-3
    • Method Detail

      • forTasks

        BuildLauncher forTasks​(java.lang.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
      • forTasks

        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
      • forTasks

        BuildLauncher forTasks​(java.lang.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
      • forLaunchables

        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
      • forLaunchables

        BuildLauncher forLaunchables​(java.lang.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
      • run

        void run​(ResultHandler<? super java.lang.Void> handler)
          throws java.lang.IllegalStateException
        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(GradleConnectionException) method is called with the appropriate exception. See run() for a description of the various exceptions that the operation may fail with.

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