Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launch multiple Gradle "spring-boot" plugin "bootRun" tasks in parallel

I have a multi-project Spring Boot application that is built using Gradle. What I'm trying to do is run the various subprojects using Spring Boot's bootRun task from the command line to do some "ad-hoc" testing via gradle bootRun. However, it seems as though each daemon starts and stops in sequence. Is there a way I can get all of my Boot daemons to run in parallel using the spring-boot plugin?

Any advice would be greatly appreciated :)

like image 916
btiernay Avatar asked May 13 '14 02:05

btiernay


1 Answers

Tasks of independent projects may be executed in parallel by using --parallel flag.

To execute a multi-project build in parallel the user must declare that they would like their projects executed in parallel, via a command-line switch:

--parallel
    \\ Tells Gradle to execute decoupled projects in parallel. Gradle will attempt to determine the optimal number of executors to use.
--max-workers=4
    \\ Tells Gradle to execute decoupled projects in parallel, using the specified number of workers. The default is the number of processors.

Similar to the Gradle Daemon, it should be possible to enable/configure parallel execution on a per-user and per-project basis. This could be done via a build environment property set in gradle.properties:

org.gradle.parallel: When set to `true`, Gradle will execute with the parallel executer

org.gradle.workers.max: Specify the maximum number of workers to use for parallel execution. This property does not in itself enable parallel execution,
                        but the value will be used whether Gradle is executed with `--parallel` or `org.gradle.parallel=true`.

Resource Links:

  • https://docs.gradle.org/current/userguide/gradle_command_line.html
  • https://docs.gradle.org/current/userguide/build_environment.html

A full parallel running example is given here: https://github.com/camiloribeiro/cucumber-gradle-parallel/blob/master/build.gradle#L50

How does parallel execution work?

First, you need to tell Gradle to use the parallel mode. You can use the command line argument (Appendix D, Gradle Command Line) or configure your build environment (Section 12.1, “Configuring the build environment via gradle.properties”). Unless you provide a specific number of parallel threads Gradle attempts to choose the right number based on available CPU cores. Every parallel worker exclusively owns a given project while executing a task. This means that 2 tasks from the same project are never executed in parallel. Therefore only multi-project builds can take advantage of parallel execution. Task dependencies are fully supported and parallel workers will start executing upstream tasks first. Bear in mind that the alphabetical scheduling of decoupled tasks, known from the sequential execution, does not really work in parallel mode. You need to make sure the task dependencies are declared correctly to avoid ordering issues.

Resource Link: https://docs.gradle.org/current/userguide/multi_project_builds.html

Since version 3.5, Gradle can print parallel workers status:

<===========--> 90% EXECUTING
> :backend-service:bootRun
> :frontend-service:bootRun
like image 51
SkyWalker Avatar answered Oct 20 '22 04:10

SkyWalker