How to Build Maven Modules in Parallel in Separate JVMs

95 Views Asked by At

We have a multi-module Maven project that takes about 2 hours to build and we would like to speed that up by making use of concurrency.

We are aware of the -T option which (as explained i.e. here) allows using multiple threads within the same JVM for the build.

Sadly, there is a lot of legacy code (which uses a lot of global states) in the project which makes executing multiple test in parallel in a single JVM very hard. Removing all of these blockers from the project would be a lot of work which we would like to avoid.

The surefire and failsafe plugins have multiple options regarding parallel execution behavior, however, as I understand it, this would only parallelize the test executions. Also, spawning a separate JVM for each test (class) seems kind of overkill to me. That would probably just as soon cause the build to take even longer than it does now.

Ideally, we would like to do the parallelization on the Maven reactor level and have it build each module in its own (single threaded) JVM with up to x JVMs running in parallel.

So my question is: is there a way to make maven create a separate JVM for each module build?
Alternatively, can we parallelize the build while making sure that tests (over all modules) are executed sequentially?

1

There are 1 best solutions below

1
J Fabian Meier On

I am not completely sure this works but I guess if you use Maven Toolchains, then each module will start its own forked JVM for the tests, not reusing already running ones.

I guess it is worth a try.