Sunday, November 19, 2017

How to launch multiple Gradle “spring-boot” plugin “bootRun” tasks in parallel?

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:

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.
Since version 3.5, Gradle can print parallel workers status:
<===========--> 90% EXECUTING
> :backend-service:bootRun
> :frontend-service:bootRun
Resource Link: https://stackoverflow.com/a/44666698/2293534

No comments:

Post a Comment