This project aims at providing faster Maven builds using techniques known from Gradle and
Takari.
Architecture overview:
mvnd embeds Maven (so there is no need to install Maven separately).
The actual builds happen inside a long living background process, a.k.a. daemon.
One daemon instance can serve multiple consecutive requests from the mvnd client.
The mvnd client is a native executable built using GraalVM.
It starts faster and uses less memory compared to starting a traditional JVM.
Multiple daemons can be spawned in parallel if there is no idle daemon to serve a build request.
This architecture brings the following advantages:
The JVM for running the actual builds does not need to get started anew for each build.
The classloaders holding classes of Maven plugins are cached over multiple builds. The plugin jars are thus read
and parsed just once. SNAPSHOT versions of Maven plugins are not cached.
The native code produced by the Just-In-Time (JIT) compiler inside the JVM is kept too. Compared to stock Maven,
less time is spent by the JIT compilation. During the repeated builds the JIT-optimized code is available
immediately. This applies not only to the code coming from Maven plugins and Maven Core, but also to all code coming
from the JDK itself.
Additional features
mvnd brings the following features on top of the stock Maven:
By default, mvnd is building your modules in parallel using multiple CPU cores. The number of utilized cores 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 build serial.
Improved console output: we believe that the output of a parallel build on a stock Maven is hard to follow. Therefore,
we implemented a simplified non-rolling view showing the status of each build thread on a separate line. This is
what it looks like on a machine with 24 cores:
Once the build is finished, the complete Maven output is forwarded to the console.
If SDKMAN! supports your operating system, it is as easy as
$ sdk install mvnd
If you used the manual install in the past, please make sure that the settings in ~/.m2/mvnd.properties still make
sense. With SDKMAN!, the ~/.m2/mvnd.properties file is typically not needed at all, because both JAVA_HOME and
MVND_HOME are managed by SDKMAN!.
# ensure to set MVND_HOME to point to your mvnd distribution, note that sdkman does it for you
$ echo'source $MVND_HOME/bin/mvnd-bash-completion.bash'>>~/.bashrc
bash is the only shell supported at this time.
Note for oh-my-zsh users
Users that use oh-my-zsh often use completion for maven. The default maven completion plugin defines mvnd as an alias to mvn deploy. So before being able to use mvnd, you need to unalias using the following command:
Optionally, you can create ~/.m2/mvnd.properties and set the java.home property in case you do not want to bother
with setting JAVA_HOME environment variable.
mvnd is designed to accept the same command line options like stock mvn (plus some extras - see below), e.g.:
mvnd clean install
mvnd specific options
--status lists running daemons
--stop kills all running daemons
The complete list of options is printed when executing mvnd --help.
Configuration
Configuration can be provided through properties file. Mvnd read properties file from the following locations:
the properties path supplied using MVND_PROPERTIES_PATH environment variable or mvnd.propertiesPath system variable
the local properties path located at [PROJECT_HOME]/.mvn/mvnd.properties
the user properties path located at: [USER_HOME]/.m2/mvnd.properties
the system properties path located at: [MVND_HOME]/conf/mvnd.properties
Properties defined in the first files will take precedence over properties specified in a lower ranked file.
A few special properties do not follow the above mechanism:
mvnd.daemonStorage: this property defines the location where mvnd stores its files (registry and daemon logs). This property can only be defined as a system property on the command line
mvnd.id: this property is used internally to identify the daemon being created
mvnd.extClasspath: internal option to specify the maven extension classpath
mvnd.coreExtensions: internal option to specify the list of maven extension to register
请发表评论