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.
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.
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.
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.
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.
It may take a little longer.
The configuration is very simple, you only need to pay attention to two things
- Make sure the
bindirectory of mvnd is associated with the
PATHif you are not using the package manager for installation.
- If you don’t have or don’t want to configure the
JAVA_HOMEenvironment variable, set
~/.m2/mvnd.propertiesto 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.
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.
To reduce learning costs mvnd is similar to the traditional Maven,
mvnd and you can also view the full list of command options via
Honestly, parallel builds are just faster, it’s a rocket ride. Also, the console output has been optimized.
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.