DEV Community

Matija Kovaček
Matija Kovaček

Posted on • Originally published at devz.life on

Speed up the Maven Build Time

How to Speed up the Maven Build Time

Recently I found out tool to speed up build time of your Maven based projects.

Maven Daemon is let's say maven wrapper which provides faster build time.

Some facts about Maven Daemon:

  • build executes in long living background process
  • native executable
  • use multiple CPU cores to build modules in parallel

More information about Maven Daemon you can find in github repository.

Maven Daemon Installation

Use sdk or brew to install Maven Daemon

$ sdk install mvnd

$ brew install mvndaemon/homebrew-mvnd/mvnd
Enter fullscreen mode Exit fullscreen mode

You can verify installation with

➜ ~ mvnd --version
mvnd native client 0.2.0-darwin-amd64 (0cd0b3f04692b7970fda06c206c1fbaac68fe9ce)
Terminal: org.jline.terminal.impl.PosixSysTerminal with pty org.jline.terminal.impl.jansi.osx.OsXNativePty
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /usr/local/Cellar/mvnd/HEAD-1c610c3/libexec/mvn
Java version: 15.0.1, vendor: N/A, runtime: /usr/local/Cellar/openjdk/15.0.1/libexec/openjdk.jdk/Contents/Home
Default locale: en_GB, platform encoding: UTF-8
OS name: "mac os x", version: "10.14.6", arch: "x86_64", family: "mac"
Enter fullscreen mode Exit fullscreen mode

Maven vs Maven Daemon build time comparison

For testing purposes I will compare build times for AEM project. Project was build 2x times before measurement.

This measurement is not perfect, since a lot of factors can affect final build time (+- few seconds), but it's fair enough to see a difference.

For testing purposes I have used AEM Project Archtype version 24.

  • mvn clean install vs mvnd clean install
    • mvn: 26.586 s
    • mvnd: 12.654 s
mvn clean install

[INFO] Reactor Summary for mysite 1.0.0-SNAPSHOT:
[INFO]
[INFO] mysite ............................................. SUCCESS [0.242 s]
[INFO] My Site - Core ..................................... SUCCESS [6.994 s]
[INFO] My Site - UI Frontend .............................. SUCCESS [11.099 s]
[INFO] My Site - Repository Structure Package ............. SUCCESS [0.795 s]
[INFO] My Site - UI apps .................................. SUCCESS [3.890 s]
[INFO] My Site - UI content ............................... SUCCESS [1.672 s]
[INFO] My Site - UI config ................................ SUCCESS [0.105 s]
[INFO] My Site - All ...................................... SUCCESS [0.138 s]
[INFO] My Site - Dispatcher ............................... SUCCESS [0.080 s]
[INFO] My Site - UI Tests ................................. SUCCESS [0.274 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 26.586 s
[INFO] Finished at: 2020-12-30T11:59:11+01:00
[INFO] ------------------------------------------------------------------------

mvnd clean install

[INFO] Reactor Summary for mysite 1.0.0-SNAPSHOT:
[INFO]
[INFO] mysite ............................................. SUCCESS [0.016 s]
[INFO] My Site - Core ..................................... SUCCESS [4.300 s]
[INFO] My Site - UI Frontend .............................. SUCCESS [10.442 s]
[INFO] My Site - Repository Structure Package ............. SUCCESS [0.178 s]
[INFO] My Site - UI apps .................................. SUCCESS [1.126 s]
[INFO] My Site - UI content ............................... SUCCESS [0.911 s]
[INFO] My Site - UI config ................................ SUCCESS [0.156 s]
[INFO] My Site - All ...................................... SUCCESS [0.107 s]
[INFO] My Site - Dispatcher ............................... SUCCESS [0.078 s]
[INFO] My Site - UI Tests ................................. SUCCESS [0.063 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 12.654 s (Wall Clock)
[INFO] Finished at: 2020-12-30T11:59:58+01:00
[INFO] ------------------------------------------------------------------------
Enter fullscreen mode Exit fullscreen mode
  • mvn clean install -PautoInstallPackage vs mvnd clean install -PautoInstallPackage
    • mvn: 29.582 s
    • mvnd: 12.995 s
mvn clean install -PautoInstallPackage

[INFO] Reactor Summary for mysite 1.0.0-SNAPSHOT:
[INFO]
[INFO] mysite ............................................. SUCCESS [0.223 s]
[INFO] My Site - Core ..................................... SUCCESS [7.354 s]
[INFO] My Site - UI Frontend .............................. SUCCESS [11.338 s]
[INFO] My Site - Repository Structure Package ............. SUCCESS [0.826 s]
[INFO] My Site - UI apps .................................. SUCCESS [4.343 s]
[INFO] My Site - UI content ............................... SUCCESS [2.885 s]
[INFO] My Site - UI config ................................ SUCCESS [0.454 s]
[INFO] My Site - All ...................................... SUCCESS [0.346 s]
[INFO] My Site - Dispatcher ............................... SUCCESS [0.061 s]
[INFO] My Site - UI Tests ................................. SUCCESS [0.374 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 29.582 s
[INFO] Finished at: 2020-12-30T12:06:29+01:00
[INFO] ------------------------------------------------------------------------

mvnd clean install -PautoInstallPackage

[INFO] Reactor Summary for mysite 1.0.0-SNAPSHOT:
[INFO]
[INFO] mysite ............................................. SUCCESS [0.005 s]
[INFO] My Site - Core ..................................... SUCCESS [4.004 s]
[INFO] My Site - UI Frontend .............................. SUCCESS [10.288 s]
[INFO] My Site - Repository Structure Package ............. SUCCESS [0.177 s]
[INFO] My Site - UI apps .................................. SUCCESS [1.433 s]
[INFO] My Site - UI content ............................... SUCCESS [1.010 s]
[INFO] My Site - UI config ................................ SUCCESS [0.292 s]
[INFO] My Site - All ...................................... SUCCESS [0.227 s]
[INFO] My Site - Dispatcher ............................... SUCCESS [0.079 s]
[INFO] My Site - UI Tests ................................. SUCCESS [0.053 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 12.995 s (Wall Clock)
[INFO] Finished at: 2020-12-30T12:08:30+01:00
[INFO] ------------------------------------------------------------------------
Enter fullscreen mode Exit fullscreen mode

Note:

Your AEM project build will fail with Maven Daemon if you use bnd-maven-plugin version older than 5.1.0

[ERROR] Failed to execute goal biz.aQute.bnd:bnd-maven-plugin:5.0.0:bnd-process (bnd-process) on project my-site.core: bnd error: null: ConcurrentModificationException -> [Help 1]
Enter fullscreen mode Exit fullscreen mode

Sum up

As test results shows, Maven Daemon build time is approximately 2x faster then normal maven. Installation is pretty much straightforward and so far didn't notice any downsides, so why not use it and save some time.

Update :

Not 100% sure, but I think installation of Maven Daemon has override my maven configuration (settings.xml).

Top comments (0)