SoFunction
Updated on 2025-04-06

Summary of the use of maven-mvnd upgraded version

Preface

In the fields of Java code compilation and construction, the most common ones are ant, maven, and gradle. These three compilation tools have their own powerful functions. At present, ant has basically been abandoned by the times. The mainstream tools are still maven and gradle, but most of the service fields of gradle are still in Android development. In terms of server development, maven is still mainstream.
However, Maven still has many shortcomings, such as the configuration based on the XML format, which is not flexible enough for gradle. In addition, the compilation speed is slow and the memory usage is high. In order to solve the problem of compilation speed, a maven-mvnd tool was born.

1. What is maven-mvnd

maven-mvnd and maven have no direct relationship, they are two completely independent projects. However, maven-mvnd is fully compatible with all the features of maven, and its usage and command operations are exactly the same as maven.
Its biggest feature is its fast compilation speed and takes up less memory. According to the official description, it can be summarized as follows:

  • mvnd embeds Maven (so no need to install Maven separately).
  • The actual construction takes place in a long-standing background process, that is, the daemon process.
  • A daemon instance can handle multiple consecutive requests from the mvnd client.
  • The mvnd client is a native executable file built using GraalVM. It starts faster and consumes less memory than launching a traditional JVM.
  • If there is no idle daemon to serve build requests, multiple daemons can be generated in parallel.
  • The JVM used to run the actual build does not need to start over for each build.
  • The class loader that saves the Maven plugin class is cached in multiple builds. Therefore, the plugin jar only needs to be read and parsed once. The SNAPSHOT version of the Maven plugin is not cached.
  • The native code generated by the real-time (JIT) compiler inside the JVM is also preserved. Compared to normal Maven, JIT compilation takes less time. During repetition generation, the JIT optimization code is immediately available. This applies not only to code from the Maven plugin and Maven Core, but also to all code from the JDK itself.

When I saw the explanation above, I felt that it was just one word: Niu B. Let's take a look at how to use it

2. Maven-mvnd installation

The installation of maven-mvnd is very simple, almost the same as the installation of maven.
First we download maven-mvnd.Click here to download

Select the appropriate version and operating system to download

  • After downloading, then unzip to the relevant directory
  • Configure environment variables and add {maven-mvnd-path}/bin to PATH
  • If you need to make the environment variables take effect on Linux or Mac systems

Then run the command in the console:

mvnd -v

If there is the following output, the installation is successful:

mvnd native client 0.7.1-darwin-amd64 (97c587c11383a67b5bd0ff8388bd94c694b91c1e)
Terminal:  with pty 
Apache Maven 3.8.3 (ff8e977a158738155dc465c6a97ffaf31982d739)
Maven home: /Users/lihao/.sdkman/candidates/mvnd/current/mvn
Java version: 17.0.9, vendor: Oracle Corporation, runtime: /Users/lihao/java/graalvm-jdk-17.0.9+11.1/Contents/Home
Default locale: zh_CN_#Hans, platform encoding: UTF-8
OS name: "mac os x", version: "12.1", arch: "x86_64", family: "mac"

Different operating systems will have different output results

Notice:

  • Windows may report an error that was not found. The solution is to install vc_redist.Click the link to download
  • There may be security issues under MacOS system, and run the following commands under the console to solve the problem:
xattr -r -d  -darwin-amd64

Replace -darwin-amd64 with your actual directory

3. Maven-mvnd packaging test

After the installation is successful, let’s now take a look at how to use maven-mvnd operation and packaging.

Normal packaging test

First, we create a new ordinary springboot project:

We first use maven to package, and we package three times in a row and run the packaging command:

mvn clean -DskipTests package

The first packing time results are as follows:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  4.202 s
[INFO] Finished at: 2024-02-23T17:54:47+08:00

The second packing time results are as follows:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  3.811 s
[INFO] Finished at: 2024-02-23T17:55:54+08:00

The result of the third packing time is as follows:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  3.779 s
[INFO] Finished at: 2024-02-23T17:56:14+08:00

The average three times is about 3.9 seconds.

Let’s use maven-mvnd to package it. The use of maven-mvnd is the same as maven. You only need to replace the mvn command with mvnd and run the package command, the same is three times:

mvnd clean -DskipTests package 

The first packing time results are as follows:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.026 s (Wall Clock)
[INFO] Finished at: 2024-02-23T17:58:21+08:00

The second packing time results are as follows:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.541 s (Wall Clock)
[INFO] Finished at: 2024-02-23T17:58:51+08:00

The result of the third packing time is as follows:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.523 s (Wall Clock)
[INFO] Finished at: 2024-02-23T17:59:07+08:00

You can see that using maven-mvnd for three packing times, each time it takes about 1.7 seconds. Correspondingly, time has increased a lot

native packaging test

Let's test springboot's native packaging. Or the above project, use native package first:

mvn clean -DskipTests native:compile -Pnative

The first time is:

[INFO] ------------------------------------------------------------------------
[INFO] Total time:  01:53 min
[INFO] Finished at: 2024-02-23T20:18:16+08:00
[INFO] ------------------------------------------------------------------------

The second time takes:

[INFO] ------------------------------------------------------------------------
[INFO] Total time:  01:30 min
[INFO] Finished at: 2024-02-23T20:21:02+08:00
[INFO] ------------------------------------------------------------------------

The third time took:

[INFO] ------------------------------------------------------------------------
[INFO] Total time:  01:23 min
[INFO] Finished at: 2024-02-23T20:22:45+08:00
[INFO] ------------------------------------------------------------------------

The average time is about 01:34 min. Next we use mvnd

Execute the same command:

mvnd clean -DskipTests native:compile -Pnative

The first time is:

[INFO] ------------------------------------------------------------------------
[INFO] Total time:  01:26 min (Wall Clock)
[INFO] Finished at: 2024-02-23T20:25:35+08:00
[INFO] ------------------------------------------------------------------------

The second time takes:

[INFO] ------------------------------------------------------------------------
[INFO] Total time:  01:28 min (Wall Clock)
[INFO] Finished at: 2024-02-23T20:27:12+08:00
[INFO] ------------------------------------------------------------------------

The third time took:

[INFO] ------------------------------------------------------------------------
[INFO] Total time:  01:33 min (Wall Clock)
[INFO] Finished at: 2024-02-23T20:31:58+08:00
[INFO] ------------------------------------------------------------------------

The average time is about 01:28 min.

It can be seen that the difference is not very big. The performance consumption of native packaging is not on maven, but on GraalVM platform.

Compilation and testing of large projects

Next we use [vertx-examples】This project is for testing

Let's clone the project first:

git clone /vert-x3/

Then use maven to compile the project:

mvn clean -DskipTests compile

First remove the compilation of the Downloading stage to ensure that there are relevant dependencies on the local area.

Compiling with maven takes time:

[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for vertx-examples 4.5.0:
[INFO] 
[INFO] core-examples ...................................... SUCCESS [  1.945 s]
[INFO] opentracing-examples ............................... SUCCESS [  0.361 s]
[INFO] zipkin-examples .................................... SUCCESS [  0.216 s]
[INFO] web-examples ....................................... SUCCESS [  3.285 s]
[INFO] web-client-examples ................................ SUCCESS [  0.180 s]
[INFO] rxjava-2-examples .................................. SUCCESS [  0.557 s]
[INFO] rxjava-3-examples .................................. SUCCESS [  0.473 s]
[INFO] unit-examples ...................................... SUCCESS [  0.048 s]
[INFO] metrics-examples ................................... SUCCESS [  0.052 s]
[INFO] micrometer-metrics-examples ........................ SUCCESS [  0.096 s]
[INFO] mail-examples ...................................... SUCCESS [  0.074 s]
[INFO] service-proxy-examples ............................. SUCCESS [  0.001 s]
[INFO] service-provider ................................... SUCCESS [  0.172 s]
[INFO] service-consumer ................................... SUCCESS [  0.075 s]
[INFO] sockjs-proxies-examples ............................ SUCCESS [  0.133 s]
[INFO] spring-examples .................................... SUCCESS [  0.001 s]
[INFO] spring-verticle-factory ............................ SUCCESS [  0.137 s]
[INFO] redis-examples ..................................... SUCCESS [  0.050 s]
[INFO] consul-examples .................................... SUCCESS [  0.042 s]
[INFO] mongo-examples ..................................... SUCCESS [  0.053 s]
[INFO] sql-client-examples ................................ SUCCESS [  0.226 s]
[INFO] shell-examples ..................................... SUCCESS [  0.167 s]
[INFO] amqp-proton-examples ............................... SUCCESS [  0.105 s]
[INFO] camel-bridge-examples .............................. SUCCESS [  0.298 s]
[INFO] circuit-breaker-examples ........................... SUCCESS [  0.054 s]
[INFO] vertx-examples ..................................... SUCCESS [  0.001 s]
[INFO] service-discovery-examples ......................... SUCCESS [  0.075 s]
[INFO] mqtt-examples ...................................... SUCCESS [  0.089 s]
[INFO] grpc-examples ...................................... SUCCESS [  3.994 s]
[INFO] kafka-examples ..................................... SUCCESS [  0.137 s]
[INFO] kotlin-coroutines-examples ......................... SUCCESS [  4.717 s]
[INFO] junit5-examples .................................... SUCCESS [  0.065 s]
[INFO] Web Api Service example ............................ SUCCESS [  0.211 s]
[INFO] cassandra-examples ................................. SUCCESS [  0.108 s]
[INFO] web-graphql-examples ............................... SUCCESS [  0.076 s]
[INFO] jpms-examples ...................................... SUCCESS [  0.225 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  18.843 s
[INFO] Finished at: 2024-02-23T21:27:47+08:00
[INFO] ------------------------------------------------------------------------

Then we use maven-mvnd to compile:

[INFO] Reactor Summary for vertx-examples 4.5.0:
[INFO] 
[INFO] core-examples ...................................... SUCCESS [  0.730 s]
[INFO] opentracing-examples ............................... SUCCESS [  0.314 s]
[INFO] zipkin-examples .................................... SUCCESS [  0.375 s]
[INFO] web-examples ....................................... SUCCESS [  3.349 s]
[INFO] web-client-examples ................................ SUCCESS [  0.431 s]
[INFO] rxjava-2-examples .................................. SUCCESS [  1.066 s]
[INFO] rxjava-3-examples .................................. SUCCESS [  1.045 s]
[INFO] unit-examples ...................................... SUCCESS [  0.160 s]
[INFO] metrics-examples ................................... SUCCESS [  0.133 s]
[INFO] micrometer-metrics-examples ........................ SUCCESS [  0.200 s]
[INFO] mail-examples ...................................... SUCCESS [  0.189 s]
[INFO] service-proxy-examples ............................. SUCCESS [  0.003 s]
[INFO] service-provider ................................... SUCCESS [  0.678 s]
[INFO] service-consumer ................................... SUCCESS [  0.185 s]
[INFO] sockjs-proxies-examples ............................ SUCCESS [  0.395 s]
[INFO] spring-examples .................................... SUCCESS [  0.002 s]
[INFO] spring-verticle-factory ............................ SUCCESS [  0.268 s]
[INFO] redis-examples ..................................... SUCCESS [  0.182 s]
[INFO] consul-examples .................................... SUCCESS [  0.071 s]
[INFO] mongo-examples ..................................... SUCCESS [  0.091 s]
[INFO] sql-client-examples ................................ SUCCESS [  0.829 s]
[INFO] shell-examples ..................................... SUCCESS [  0.444 s]
[INFO] amqp-proton-examples ............................... SUCCESS [  0.289 s]
[INFO] camel-bridge-examples .............................. SUCCESS [  0.629 s]
[INFO] circuit-breaker-examples ........................... SUCCESS [  0.111 s]
[INFO] vertx-examples ..................................... SUCCESS [  0.003 s]
[INFO] service-discovery-examples ......................... SUCCESS [  0.177 s]
[INFO] mqtt-examples ...................................... SUCCESS [  0.247 s]
[INFO] grpc-examples ...................................... SUCCESS [  5.308 s]
[INFO] kafka-examples ..................................... SUCCESS [  0.427 s]
[INFO] kotlin-coroutines-examples ......................... SUCCESS [  1.570 s]
[INFO] junit5-examples .................................... SUCCESS [  0.079 s]
[INFO] Web Api Service example ............................ SUCCESS [  0.752 s]
[INFO] cassandra-examples ................................. SUCCESS [  0.259 s]
[INFO] web-graphql-examples ............................... SUCCESS [  0.290 s]
[INFO] jpms-examples ...................................... SUCCESS [  0.221 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  5.778 s (Wall Clock)
[INFO] Finished at: 2024-02-23T21:29:11+08:00
[INFO] ------------------------------------------------------------------------

It can be seen that maven-mvnd has a great advantage when compiling complex projects.

Summarize

There is no difference between using maven-mvnd and maven. Just use the mvnd command to replace mvn.

The difference between these two is very small when compiling small projects, but in the case of large projects, the advantages of maven-mvnd are still very obvious.

maven-mvnd mainly optimizes performance for Java code compilation. However, there should be no performance improvement for third-party plug-ins. Because the execution efficiency of the plug-in still depends on the execution logic of the plug-in itself.

This is the article about the use of maven-mvnd upgraded version of maven. For more related content on maven-mvnd, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!