One of the biggest disadvantages of Maven, which is often compared to Gradle, is that Maven builds slowly, Gradle builds 2 to 10 times faster than Maven, and today Maven can be faster as well. The Apache Maven team took inspiration from Gradle and Takari (Maven lifecycle optimizer) to make enhancements to Maven, resulting in the maven-mvnd project.

Brief introduction

mvnd is not a refactoring of Maven, but rather has Maven built in. It is actually one or more Maven daemons used to perform the actual build services. A single daemon instance can serve Maven builds for multiple consecutive requests from mvnd clients. When there are no idle daemons to support build requests, mvnd can generate multiple daemons in parallel

Using GraalVM instead of JVM

mvnd is fast because it uses GraalVM instead of the traditional JVM, so it starts faster, uses less memory, and doesn’t need to start a new JVM for each build when implementing a build. In addition the Maven plugin no longer needs to be loaded multiple times at build time, but is cached across multiple builds. SNAPSHOT versions of Maven plugins are not cached.

JIT support

The JIT (Just In Time) real-time compilation feature of GraalVM is also used in Maven build jobs. JIT can greatly reduce compilation time, and JIT optimized code is immediately available during repeated builds, which also greatly improves build efficiency.

Parallel builds

Currently Maven 3’s parallel builds are still experimental and require that the plugins used must be thread-safe. By default, mvnd supports parallel builds using multiple CPU cores. Of course, if your source code does not support parallel builds, you can switch to serial builds by adding the - T1 parameter.

A simple attempt

Next, a brief attempt at mvnd.

Installation

Currently mvnd has support for Linux, MacOS, Windows platforms. You can install them through SDKMAN, Homebrew, Chocolatey package managers respectively. You can also go directly to mvnd distribution repository to download the corresponding binary for installation. Here is an example of Windows, I choose Chocolatey to install.

1
choco install mvndaemon

It may take a little longer.

Configuration

The configuration is very simple, you only need to pay attention to two things

  • Make sure the bin directory of mvnd is associated with the PATH if you are not using the package manager for installation.
  • If you don’t have or don’t want to configure the JAVA_HOME environment variable, set java.home in ~/.m2/mvnd.properties to specify the Java directory, for example: java.home=C:\\AdoptOpenJDK\\\jdk-8. Please ignore this article if you have already configured environment variables.

Other configuration items can be found in mvnd configuration.

Use

After the installation and configuration is complete, the command line execution of mvnd --version will show the following result to indicate that the installation is successful.

1
2
3
4
5
6
7
8
mvnd --version
mvnd native client 0.7.1-windows-amd64 (97c587c11383a67b5bd0ff8388bd94c694b91c1e)
Terminal: org.jline.terminal.impl.jansi.win.JansiWinSysTerminal
Apache Maven 3.8.3 (ff8e977a158738155dc465c6a97ffaf31982d739)
Maven home: C:\Program Files\mvndaemon\mvnd-0.7.1-windows-amd64\mvn
Java version: 1.8.0_282, vendor: AdoptOpenJDK, runtime: C:\Program Files\AdoptOpenJDK\jdk-8.0.282.8-hotspot\jre
Default locale: zh_CN, platform encoding: GBK
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

To reduce learning costs mvnd is similar to the traditional Maven, mvn becomes mvnd and you can also view the full list of command options via mvnd --help.

Honestly, parallel builds are just faster, it’s a rocket ride. Also, the console output has been optimized.

image

Thanks to GraalVM, this tool is likely to extend the life of Maven and avoid being pulled ahead of Gradle too soon. For us, this project can be a wait-and-see project to see what further moves Apache Maven officials make.