Maven-mvnd is a faster build tool for Java developers who are tired of the slow build of Maven, but can’t switch to a faster build tool due to historical burden and usage habits.

introduce

Maven-mvnd is a faster build tool that the Apache Maven team borrowed from Gradle and Takari. MVND is embedded with Maven, and it is for this reason that we can seamlessly switch from Maven to MVND (no separate Maven installation is required either).

By design, MVND generates one or more daemons to service build requests in parallel. In addition, MVND uses GraalVM to replace the traditional JVM, which is faster to boot and takes up less memory.

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

  • Run builtJVMThere is no need to restart for each build.
  • MavenThe class loader cache for plug-in classes exists in multiple builds, plug-insjarsIt will only be read and parsed once.
  • JVMIn theJITThe generated native code is retained. withMavenCompared to theJITCompilation takes less time. During repeated builds,JITOptimized code is available immediately. This doesn’t just apply to people fromMavenPlug-in andMavenKernel code also applies fromJDKAll the code itself.

By default, MVND uses multiple CPU cores to build modules in parallel. 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 serialize your builds.

At the same time, the official release of the 24-core machine running dynamic graph:

The installation

For the installation of MVND, the official documentation gives a very detailed tutorial, recommended first read: github.com/apache/mave… .

Author is through Homebrew to install, practice proves that macOS M1 installation is no problem. However, it is important to note that the MVND version installed in this way is 0.7.1, and tests on Ubuntu and macOS M1 show that this version does not support JDK8, while the JDK11 shown in the official example is fine. Running the MVND command in JDK8 causes 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.accessThe $100(URLClassLoader.java:74)
	at java.net.URLClassLoaderThe $1.run(URLClassLoader.java:369)
	at java.net.URLClassLoaderThe $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)
	at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:601)
Copy the code

It is expected that the execution files downloaded in this way are compiled with older JDK versions and will not run on older versions because they lack certain methods or features. Maven-mvnd: Versions of MVND and Maven #512 A solution to this problem is to set the version specified by JAVA_HOME to JDK11 and run the MVND command with the parameter -dmaven.com piler.release=8, that is

mvnd -Dmaven.compiler.release=8 compile
Copy the code

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

In issue #512, the author said that the lowest supported version of MVND is JDK8, but I tried it from 0.5.2 and still reported the same error… Maybe there is something wrong with my computer, because I have seen other people Posting results showing that the latest version of JDK8 can be installed and used. Alternatively, if that doesn’t work, you might be able to manually compile the source code to generate the executable, as described in the official readme.

use

The use of Maven is exactly the same as that of Maven, just change the command MVN to MVND. Compared with the traditional Maven, the time consumed by MVND construction is 1/2 of the original.

conclusion

In this paper, the author introduces maven-MVND, installation, use and some abnormal situations. If you want to know more details, you can read the official documentation. Maven might not be as good as Gradle, but it’s a nice change in the context of historical baggage and usage habits.

In addition, the views of this article only represent the author’s personal, if there is a mistake, please point out in time.

reference

  • Github.com/apache/mave…
  • Github.com/apache/mave…
  • Mp.weixin.qq.com/s/TG_6vq0mg…