Parallel builds in Maven 3

Nuttapon Pinitpaitoon
blog blog
Published in
3 min readJun 6, 2019
https://themomentum.co/belt-and-road-initiative/

Maven 3.x has the capability to perform parallel builds. The command is as follows:

mvn -T 4 clean install # Builds with 4 threads
mvn -T 1C clean install # 1 thread per cpu core
mvn -T 1.5C clean install # 1.5 thread per cpu core

This build-mode analyzes your project’s dependency graph and schedules modules that can be built in parallel according to the dependency graph of your project.

The above mentioned thread per cpu core means the number of cores is used as a multiplier

Experimental feature for 3.0!

The parallel build feature has been subject to extensive testing, but the maven ecosystem is diverse so there will be undiscovered issues. We recommend that users of the parallel build feature establish their own reference as to how well this works for their project, preferably starting with everyday builds as opposed to final production releases.

The parallel build functionality is brand new, and although they are tested with quite a few projects they do not have the general wisdom accumulated by running on multiple project types on multiple platforms within the community. So take a little care.

What performance boost can be expected ?

This depends greatly on your module structure, but the following observations have been made:

  • 20–50% speed improvement is quite common.
  • Distributing tests among your modules is likely to improve performance, putting all your tests in one module decreases it — unless you run one of the parallel surefire test providers.
  • Running tests in parallel within a single surefire-instance is a little different from running multiple surefire-runs (from separate projects), since there will be different classloaders. Remember that tcp/ip ports and files are still singletons.

ทดสอบ clean install กับ Project BWM

Spec : Core i5–4460 @3.2Ghz, RAM 8 GB, SSD, Windows 10 x64, jdk 1.8.0_191, maven 3.3.9

mvn clean install

mvn -T 2 clean install

mvn -T 1C clean install

Reference

--

--