Technologies

Let’s talk about mvnd

Mvnd is a tool that acts as a Maven wrapper, making Maven builds much faster (using Gradle techniques).

Its most important features include these:

  • mvnd comes built-in with Maven, so you don’t need to install Maven separately.
  • Maven builds are done inside a daemon process (mvnd from mvn + Daemon), so you don’t need to run a new JVM for each build.
  • A daemon instance can serve multiple consecutive requests from the mvnd client.
  • mvnd is a native executable built with GraalVM, so it starts faster and uses less memory compared to starting a traditional JVM.
  • Class-loaders containing Maven plugin classes are cached for several builds, plugin jars are read and parsed only once. SNAPSHOT versions of Maven plugins are not cached.
  • Native code produced by the Just-In-Time (JIT) compiler inside the JVM is also maintained. Compared to the original Maven, JIT compilation takes less time. During repeated builds, the JIT-optimised code is immediately available. This applies not only to code coming from Maven plugins and Maven Core, but also to all code coming from the JDK itself.
  • By default, mvnd builds its modules in parallel using multiple CPU cores. The number of cores used is given by the following formula:

    Math.max(Runtime.getRuntime().availableProcessors() – 1, 1)

  • If the project source tree does not support parallel builds, you can pass -T1 on the command line to do the serial build.

Installation

There are several ways to install, but for this case we will use the manual method:

  • Download the appropriate ZIP for the platform we are working from, fromthe repository.
  • Unzip the files in the folder we need.
  • Add the bin directory to the PATH.
  • Optionally, we can create a «~/.m2/mvnd.properties»” and set the property «java.home», in case we don’t want to set the environment variable JAVA_HOME.
  • Lastly, to test if mvnd works, we will launch «mvnd –version». If all goes well, we should get something like this:

In case you get the following message in a Windows environment: «VCRUNTIME140.dll was not found» , then you will need to install the executable«vc_redist.x64.exe» from the Microsoftt support page (related issue).

Improvements

In the following screenshots, you can see the difference between mvn and mvnd:

mvn clean

mvnd clean

mvnd install

✍🏻 Author(s)

Leave a Reply