Maven official announcement: Get rid of Maven and Gradle, a new generation of stronger, faster and more powerful build tools is coming!

e3e8085972d31bf1587443d05c02f550.png

Source: https://blog.csdn.net/weixin_48321993/article/details/125979820

I believe that as a Java developer, you have already had enough of maven's slow compilation, but due to historical burdens, usage habits and other issues, you can't switch to other faster build tools for the time being. Here I will introduce you to a faster maven—— maven-mvnd.

1. Introduction

maven-mvnd is a faster build tool derived from the Apache Maven team after borrowing Gradle and Takari. Mvnd embeds Maven, and it is for this reason that we can seamlessly switch Maven to mvnd (no need to install Maven separately).

In terms of design, one or more daemon processes are generated in mvnd to serve build requests to achieve the effect of parallel builds. In addition, in the choice of VM, mvnd uses GraalVM to replace the traditional JVM. Compared with it, GraalVM starts faster and takes up less memory.

According to the documentation, mvnd has the following advantages over traditional Maven:

  • The JVM running the build does not need to be restarted for each build.

  • The class loader for Maven plugin classes is cached across multiple builds, plugin jars are only read and parsed once.

  • The native code generated by the JIT in the JVM is preserved. JIT compilation takes less time compared to Maven. During repeated builds, JIT-optimized code is immediately available. This applies not only to code from Maven Plugins and Maven Core, but also to all code from the JDK itself.

By default, mvnd builds modules in parallel using multiple CPU cores. The number of cores used is given by the formula Math.max(Runtime.getRuntime().availableProcessors() - 1, 1). If your source tree does not support parallel builds, pass -T1 on the command line to make your builds serial.

At the same time, the official gave a dynamic diagram of running on a 24-core machine:

9ed267a4b3bb495d91287ff4233959a4.gif

2. Installation

For the installation of mvnd, the official document gives a very detailed tutorial, it is recommended to read first: https://github.com/apache/maven-mvnd

The author installed it through Homebrew, and practice has proved that there is no problem with the installation and use of macOS m1. However, it should be noted that the mvnd version installed in this way is 0.7.1, and after testing on ubuntu and macOS m1, it is found that this version does not support JDK8 (maybe it is only a problem with the author's computer), but as shown in the official example JDK11 is indeed no problem. Running the mvnd command on JDK8 produces the following error:

~ % 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
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:757)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:473)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:419)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
at java.lang.ClassLoader.loadClass(ClassLoader.java:352)

It is estimated that the executable file downloaded in this way is compiled by a higher version of JDK, and it cannot run on a lower version because it lacks some methods or features. When I was at a loss, the author found a Closed issues: Different java versions for mvnd and maven #512 from the update instructions of the latest version of maven-mvnd. The author provided a solution to this problem is to set the version specified by JAVA_HOME Set it to JDK11, and add the parameter -Dmaven.compiler.release=8 when running the mvnd command, that is

mvnd -Dmaven.compiler.release=8 compile

In this way, the compiled code corresponding to JDK8 can be generated.

For issue #512, the author responded that the minimum supported version of mvnd is JDK8, but the author started to try from 0.5.2 and still reported the same error... Maybe there is a certain problem with the author's computer, because I saw other people posting The result graph shows that the latest version under JDK8 can also be installed and used. In addition, if it still doesn't work, maybe we can generate an executable file by manually compiling the source code. The specific steps have been given in the official readme.

3. Use

The usage is exactly the same as that of Maven, just change the command mvn to mvnd.

In the actual measurement of the author's machine, compared with the traditional Maven, the time spent on building through mvnd is 1/2 of the original.

Four. Summary

The author of this article starts from the introduction, installation, use and some abnormal situations of maven-mvnd. If readers want to know more details, they can read the official documents.

And maybe the enhanced Maven is still not as good as Gradle, but this enhancement of Maven is still very fragrant under the background of historical burden and usage habits.

------

We have created a high-quality technical exchange group. When you are with excellent people, you will become excellent yourself. Hurry up and click to join the group and enjoy the joy of growing together. In addition, if you want to change jobs recently, I spent 2 weeks a year ago collecting a wave of face-to-face experience from big factories. If you plan to change jobs after the festival, you can click here to claim it !

recommended reading

··································

Hello, I am DD, a programmer. I have been developing a veteran driver for 10 years, MVP of Alibaba Cloud, TVP of Tencent Cloud. From general development to architect to partner. Along the way, my deepest feeling is that we must keep learning and pay attention to the frontier. As long as you can persevere, think more, complain less, and work hard, it will be easy to overtake on corners! So don't ask me if it's too late to do what I do now. If you are optimistic about something, you must persevere to see hope, not to persevere only when you see hope. Believe me, as long as you stick to it, you will be better than now! If you have no direction yet, you can follow me first, and I will often share some cutting-edge information here to help you accumulate capital for cornering and overtaking.

Guess you like

Origin blog.csdn.net/j3T9Z7H/article/details/131297605