18

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 :)

btiernay
  • 7,873
  • 5
  • 42
  • 48
  • 1
    Have you tried with Gradle's parallel mode (`--parallel`)? For more details on this mode, see the [Gradle User Guide](http://gradle.org/docs/current/userguide/userguide_single.html). – Peter Niederwieser May 13 '14 at 02:17
  • @PeterNiederwieser Much closer, thanks!. Still having some issues though, but it may have to do with stdin, which I believe there is a simple fix for. Cheers! – btiernay May 13 '14 at 02:21
  • @PeterNiederwieser actually, http://stackoverflow.com/questions/13172137/console-application-with-java-and-gradle doesn't seem to work. I'm basically blocking on `System.in.read()`. Is there a recommended way to prevent shutdown with `bootRun`? Cheers – btiernay May 13 '14 at 02:39
  • I'm not familiar with Spring Boot and its Gradle plugin. – Peter Niederwieser May 13 '14 at 02:45
  • @PeterNiederwieser I got everything working somewhat. Turned out one of my applications didn't have a non-daemon thread so it was exiting prematurely since stdin wasn't available to block on. One thing I notice is that when I `SIGTERM` gradle it leaves orphaned `--parallel` processes. Is that to be expected? – btiernay May 13 '14 at 11:53

1 Answers1

13

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:

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
Community
  • 1
  • 1
SkyWalker
  • 28,384
  • 14
  • 74
  • 132
  • 1
    Is there a way to specify order that apps should start in? such as backend must start before frontend? – Rylander May 29 '18 at 17:32
  • @MikeRylander For sequential, you can check https://github.com/camiloribeiro/cucumber-gradle-parallel/blob/master/build.gradle#L80 – SkyWalker May 29 '18 at 17:36