1

Introduction to Maven Daemon (mvnd)

 1 year ago
source link: http://www.mastertheboss.com/jboss-frameworks/jboss-maven/introduction-to-maven-daemon-mvnd/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Maven Daemon (mvnd) is a background process that can speed up Maven builds by keeping a daemon process running in the background. This allows Maven to start up faster, as it does not have to initialize the build process from scratch for each build. In this tutorial, we will cover how to install and configure mvnd, as well as how to use it to speed up your Maven builds.

Installing and Configuring Maven Daemon

The GitHup project of Maven Daemon contains the installation instructions:https://github.com/apache/maven-mvnd#how-to-install-mvnd

To install it manually, download the latest ZIP suitable for your platform from https://downloads.apache.org/maven/mvnd/

Once mvnd is installed and configured, you can use it to speed up your Maven builds. To use mvnd, simply run the mvnd command instead of the mvn command when building your project.

For example, to build a Maven project with mvnd, you would run the following command:

mvnd clean install
mvnd clean install

This will start the mvnd daemon process in the background, and then run the clean and install goals of the Maven build.

By default, mvnd is building your modules in parallel using multiple CPU cores. To check the number of CPUs on your machines, you can use several commands. For example, with lscpu:

lscpu | egrep 'Model name|Socket|Thread|NUMA|CPU\(s\)'
CPU(s): 12
On-line CPU(s) list: 0-11
Model name: Intel(R) Core(TM) i7-10850H CPU @ 2.70GHz
Thread(s) per core: 2
Socket(s): 1
NUMA node(s): 1
NUMA node0 CPU(s): 0-11
lscpu | egrep 'Model name|Socket|Thread|NUMA|CPU\(s\)'
CPU(s):                          12
On-line CPU(s) list:             0-11
Model name:                      Intel(R) Core(TM) i7-10850H CPU @ 2.70GHz
Thread(s) per core:              2
Socket(s):                       1
NUMA node(s):                    1
NUMA node0 CPU(s):               0-11

Benefits of mvnd

One of the key benefits of using mvnd is that it can significantly reduce the time it takes to start up a Maven build. It achieves this by starting a daemon in the background that maintains a cache of the build artifacts and class files, allowing subsequent builds to be faster.

Besides, mvnd is faster than Maven because it is implemented as a native executable built with GraalVM, which allows it to avoid the overhead of starting a new Java Virtual Machine (JVM) for each build.

The speedup achieved by mvnd depends on the size and complexity of the project being built. For small projects with a few modules, mvnd can provide a speedup of 7-10 times or more compared to stock Maven. For larger projects with many modules, mvnd can provide a speedup of 3-5 times or more, due to its ability to build modules in parallel and the optimization provided by the JIT compiler.

Let’s check the performance of mvnd by building a Maven multi-module project which includes a consistent number of sub-projects.

Testing mvnd

In order to test mvnd, I will run a multi-project build of the Jakarta EE 10 examples from Practical Enterprise Development, which includes 85 Maven projects.

Firstly, let’s check the performance of the standard Maven build:

mvnd tutorial

Next, let’s run the build again with mvnd :

introduction to mvnd daemon

Conclusion

For larger projects with many modules, mvnd can provide a speedup of 3-5 times or more, due to its ability to build modules in parallel and the optimization provided by the JIT compiler. Overall, mvnd can save a significant amount of time in the build process, making it a useful tool for developers working with Maven projects

Post Views: 120

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK