Boost Java Build Speed: How Maven‑mvnd Outperforms Traditional Maven
maven‑mvnd, an Apache‑backed build tool that embeds Maven and leverages GraalVM, speeds up Java project compilation by reusing JVM processes, caching plugin classloaders, and retaining JIT‑generated code, with parallel module builds and simple mvn‑to‑mvnd command substitution, though JDK version quirks may require workarounds.
Java developers often suffer from Maven's slow compilation, but cannot easily switch to faster build tools due to legacy constraints; this article introduces Maven‑mvnd, a faster Maven alternative.
1. Introduction
maven‑mvnd is a faster Maven derived from Gradle and Takari, embedding Maven so you can switch without separate installation.
It runs one or more daemon processes to serve build requests, achieving parallel builds. It uses GraalVM instead of the traditional JVM, which starts faster and uses less memory.
Compared with traditional Maven, mvnd offers advantages:
JVM for builds does not need to restart for each build.
Plugin classloader is cached across builds, so plugin JARs are read and parsed only once.
JIT‑generated native code in the JVM is retained, reducing JIT compilation time; the optimized code is immediately available for repeated builds, benefiting both Maven plugins and core JDK code.
By default mvnd builds modules in parallel using multiple CPU cores, determined by Math.max(Runtime.getRuntime().availableProcessors() - 1, 1). Use -T1 to force serial builds if the source tree does not support parallelism.
The following GIF shows dynamic performance on a 24‑core machine:
2. Installation
The official documentation provides detailed installation steps at https://github.com/apache/maven-mvnd. The author installed mvnd via Homebrew on macOS M1, which works, but the Homebrew version (0.7.1) does not support JDK 8, only JDK 11.
Running mvnd with JDK 8 produces an error like:
~ % mvnd -v
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/mvndaemon/mvnd/client/DefaultClient has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
...To compile for JDK 8, set JAVA_HOME to JDK 11 and add the parameter -Dmaven.compiler.release=8 when invoking mvnd:
mvnd -Dmaven.compiler.release=8 compileThis generates bytecode compatible with JDK 8.
If the issue persists, building mvnd from source as described in the official README is an alternative.
3. Usage
Usage is identical to Maven; simply replace the mvn command with mvnd.
In the author's tests, mvnd reduced build time to roughly half of that with traditional Maven.
4. Conclusion
The article covered mvnd’s features, installation, usage, and some encountered issues. For more details, refer to the official documentation. While Gradle may still be faster, mvnd offers a compelling speed boost for developers tied to Maven.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Programmer DD
A tinkering programmer and author of "Spring Cloud Microservices in Action"
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
