CLOVER🍀

That was when it all began.

Apache Mavenをdaemonずしお実行する、Maven Daemonmvndを詊す

これは、なにをしたくお曞いたもの

Apache Mavenをdaemonずしお実行できるずいうMaven Daemonを詊しおみようかなずいうこずで。

Maven Daemonmvnd

Maven DaemonのGitHubリポゞトリヌはこちら。

GitHub - apache/maven-mvnd: Apache Maven Daemon

GradleやTakariで知られおいる技術を䜿っお、より高速なMavenビルドを提䟛するこずを目的ずしおいるそうなのですが。

This project aims at providing faster Maven builds using techniques known from Gradle and Takari.

Gradleはさおおき、Takariはなんでしたっけず思ったんですが、過去にMaven Wrapperを開発しおいたずころですね。

takari · GitHub

Maven Wrapperは今はApacheに移っおいたす。

Apache Maven Wrapper – Maven Wrapper

特城ずしおは以䞋のようです。

  • mvndコマンドで実行するが、Maven自䜓は組み蟌たれおいるMavenのむンストヌルは䞍芁
  • 実際のビルドはバックグラりンドで実行されるdaemonプロセスで実行される
  • ひず぀のdaemonむンスタンスで、mvndクラむアントからの連続した芁求を凊理できる
  • mvndはGraalVMで䜜られたネむティブむメヌゞ
  • ビルドのリク゚ストに察しおアむドルのdaemonがない堎合は、耇数のdaemonを䞊行で生成可胜

利点ずしおは以䞋のようです。

  • ビルド時のJavaVM起動のオヌバヌヘッドを削枛できる
  • Mavenプラグむンをキャッシュする
  • JITコンパむラによっお生成されたネむティブコヌドもキャッシュされ、暙準のMavenず比范するずJITコンパむルにかかる時間が短くなる
    • 繰り返しビルドするずJIT最適化されたコヌドをすぐ埗られるようになる

mvnd - the Maven Daemon / Introduction

たた、デフォルトで䞊列ビルドを行うずずもに、䞊列ビルド時のコン゜ヌル出力を改善しおいるようです。

mvnd - the Maven Daemon / Additional features

OSはLinux、macOS、Windowsいずれでも倧䞈倫そうな感じですね。

䜿い方自䜓はmvnコマンドをmvndコマンドに眮き換えお䜿うむメヌゞで、これにdaemonの操䜜が加わりたす。

Maven Daemon固有の蚭定ファむルもあるようです。配眮堎所は以䞋ですね。䞊にいくほど優先床が高くなりたす。

  • 環境倉数MVND_PROPERTIES_PATHたたはシステムプロパティmvnd.propertiesPathで指定したファむル
  • プロゞェクトのロヌカル蚭定ファむル 
 [PROJECT_HOME]/.mvn/mvnd.properties
  • ナヌザヌ単䜍の蚭定ファむル 
 [USER_HOME]/.m2/mvnd.properties
  • システム党䜓の蚭定ファむル 
 [MVND_HOME]/conf/mvnd.properties

mvnd - the Maven Daemon / Configuration

蚭定項目はこちらを参照。

https://github.com/apache/maven-mvnd/blob/1.0.1/dist/src/main/distro/conf/mvnd.properties

mvnd.daemonStorage、mvnd.id、mvnd.extClasspath、mvnd.coreExtensionsは特殊なプロパティで、mvnd.daemonStorageのみ
システムプロパティで蚭定ができるようです。

個人的にはあたりMavenの実行速床が気になったこずはないのですがテストの実行を速くしたいなどはたくさんありたすが 、
1床詊しおおこうかなずいうこずで。

環境

今回の環境はこちら。

$ java --version
openjdk 21.0.3 2024-04-16
OpenJDK Runtime Environment (build 21.0.3+9-Ubuntu-1ubuntu122.04.1)
OpenJDK 64-Bit Server VM (build 21.0.3+9-Ubuntu-1ubuntu122.04.1, mixed mode, sharing)

OSはUbuntu Linux 22.04 LTSです。

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.4 LTS
Release:        22.04
Codename:       jammy


$ uname -srvmpio
Linux 5.15.0-113-generic #123-Ubuntu SMP Mon Jun 10 08:16:17 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

Apache Mavenはむンストヌル䞍芁ずいうこずなので、今回は導入しおいたせん。

たたSDKMANは導入枈みずしたす。

$ sdk version

SDKMAN!
script: 5.18.2
native: 0.1.3

Maven Daemonmvndをむンストヌルする

たずはmvndをむンストヌルしたす。

mvnd - the Maven Daemon / How to install mvnd

むンストヌル方法はいく぀かありたす。

  • SDKMAN
  • Homebrew
  • MacPorts、Chocolatey、Scoop、asdf
  • バむナリをダりンロヌド

バむナリをダりンロヌドする堎合は、以䞋から取埗したす。

Index of /maven/mvnd

今回はSDKMANでむンストヌルしたす。

$ sdk install mvnd

バヌゞョンを確認。

$ mvnd --version
Apache Maven Daemon (mvnd) 1.0.1 linux-amd64 native client (621c13a190faf99724130a4dd0b8ec473a9cde44)
Terminal: org.jline.terminal.impl.PosixSysTerminal with pty org.jline.terminal.impl.jni.linux.LinuxNativePty
Apache Maven 3.9.8 (36645f6c9b5079805ea5009217e36f2cffd34256)
Maven home: $HOME/.sdkman/candidates/mvnd/1.0.1/mvn
Java version: 21.0.3, vendor: Ubuntu, runtime: /usr/lib/jvm/java-21-openjdk-amd64
Default locale: ja_JP, platform encoding: UTF-8
OS name: "linux", version: "5.15.0-113-generic", arch: "amd64", family: "unix"

Maven Daemon 1.0.1がむンストヌルされたした。Apache Mavenは3.9.8のようです。

ちなみに、このコマンドを実行した時点でMaven Daemonが起動しおたりしたす。なので初回の実行はちょっず重いです。

$ jcmd -l
35414 jdk.jcmd/sun.tools.jcmd.JCmd -l
35163 org.codehaus.plexus.classworlds.launcher.Launcher

こんなプロセスが起動しおいたす。

$ ps aux | grep org.codehaus.plexus.classworlds.launcher.Launcher
xxxxx   35163  1.6  0.6 7690780 99628 pts/4   Sl   21:10   0:05 /usr/lib/jvm/java-21-openjdk-amd64/bin/java -classpath $HOME/.sdkman/candidates/mvnd/1.0.1/mvn/boot/plexus-classworlds-2.8.0.jar -javaagent:$HOME/.sdkman/candidates/mvnd/1.0.1/mvn/lib/mvnd/mvnd-agent-1.0.1.jar -Dmvnd.home=$HOME/.sdkman/candidates/mvnd/1.0.1 -Dmaven.home=$HOME/.sdkman/candidates/mvnd/1.0.1/mvn -Dmaven.conf=$HOME/.sdkman/candidates/mvnd/1.0.1/mvn/conf -Dclassworlds.conf=$HOME/.sdkman/candidates/mvnd/1.0.1/bin/mvnd-daemon.conf -Dorg.slf4j.simpleLogger.logFile=$HOME/.m2/mvnd/registry/1.0.1/daemon-fc35606d.log -Dmvnd.java.home=/usr/lib/jvm/java-21-openjdk-amd64 -Dmvnd.id=fc35606d -Dmvnd.daemonStorage=$HOME/.m2/mvnd/registry/1.0.1 -Dmvnd.registry=$HOME/.m2/mvnd/registry/1.0.1/registry.bin -Dmvnd.socketFamily=inet -Dmvnd.home=$HOME/.sdkman/candidates/mvnd/1.0.1 -Djdk.java.options=--add-opens java.base/java.io=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/sun.net.www.protocol.jar=ALL-UNNAMED --add-opens java.base/sun.nio.fs=ALL-UNNAMED -Dmvnd.noDaemon=false -Dmvnd.debug=false -Dmvnd.debug.address=8000 -Dmvnd.idleTimeout=3h -Dmvnd.keepAlive=100ms -Dmvnd.extClasspath= -Dmvnd.coreExtensions= -Dmvnd.enableAssertions=false -Dmvnd.expirationCheckDelay=10s -Dmvnd.duplicateDaemonGracePeriod=10s -Dmvnd.socketFamily=inet org.codehaus.plexus.classworlds.launcher.Launcher
xxxxx   35468  0.0  0.0  10320  2416 pts/4    S+   21:16   0:00 grep --color=auto org.codehaus.plexus.classworlds.launcher.Launcher

むンストヌルされたディレクトリの䞭身はこちら。確かにApache Mavenそのものが含たれおいたす。

$ tree ~/.sdkman/candidates/mvnd/1.0.1
$HOME/.sdkman/candidates/mvnd/1.0.1
├── LICENSE.txt
├── NOTICE.txt
├── README.adoc
├── bin
│   ├── mvnd
│   ├── mvnd-bash-completion.bash
│   ├── mvnd-client.conf
│   ├── mvnd-daemon.conf
│   ├── mvnd.cmd
│   ├── mvnd.sh
│   └── platform-linux-amd64
├── conf
│   └── mvnd.properties
└── mvn
    ├── LICENSE
    ├── NOTICE
    ├── README.txt
    ├── bin
    │   ├── m2.conf
    │   ├── mvn
    │   ├── mvn.cmd
    │   ├── mvnDebug
    │   ├── mvnDebug.cmd
    │   └── mvnyjp
    ├── boot
    │   ├── plexus-classworlds-2.8.0.jar
    │   └── plexus-classworlds.license
    ├── conf
    │   ├── logging
    │   │   ├── java.util.logging.properties
    │   │   └── simplelogger.properties
    │   ├── settings.xml
    │   └── toolchains.xml
    └── lib
        ├── aopalliance-1.0.jar
        ├── aopalliance.license
        ├── commons-cli-1.8.0.jar
        ├── commons-cli.license
        ├── commons-codec-1.16.1.jar
        ├── commons-codec.license
        ├── ext
        │   ├── README.txt
        │   ├── hazelcast
        │   │   └── README.txt
        │   └── redisson
        │       └── README.txt
        ├── failureaccess-1.0.2.jar
        ├── failureaccess.license
        ├── guava-33.2.1-jre.jar
        ├── guava.license
        ├── guice-5.1.0.jar
        ├── guice.license
        ├── httpclient-4.5.14.jar
        ├── httpclient.license
        ├── httpcore-4.4.16.jar
        ├── httpcore.license
        ├── jansi-2.4.1.jar
        ├── jansi-native
        │   ├── README.txt
        │   └── Windows
        │       ├── arm64
        │       │   └── libjansi.so
        │       ├── x86
        │       │   └── jansi.dll
        │       └── x86_64
        │           └── jansi.dll
        ├── jansi.license
        ├── javax.annotation-api-1.3.2.jar
        ├── javax.annotation-api.license
        ├── javax.inject-1.jar
        ├── javax.inject.license
        ├── jcl-over-slf4j-1.7.36.jar
        ├── jcl-over-slf4j.license
        ├── jul-to-slf4j-1.7.36.jar
        ├── maven-artifact-3.9.8.jar
        ├── maven-builder-support-3.9.8.jar
        ├── maven-compat-3.9.8.jar
        ├── maven-core-3.9.8.jar
        ├── maven-embedder-3.9.8.jar
        ├── maven-model-3.9.8.jar
        ├── maven-model-builder-3.9.8.jar
        ├── maven-plugin-api-3.9.8.jar
        ├── maven-repository-metadata-3.9.8.jar
        ├── maven-resolver-api-1.9.20.jar
        ├── maven-resolver-connector-basic-1.9.20.jar
        ├── maven-resolver-impl-1.9.20.jar
        ├── maven-resolver-named-locks-1.9.20.jar
        ├── maven-resolver-provider-3.9.8.jar
        ├── maven-resolver-spi-1.9.20.jar
        ├── maven-resolver-transport-file-1.9.20.jar
        ├── maven-resolver-transport-http-1.9.20.jar
        ├── maven-resolver-transport-wagon-1.9.20.jar
        ├── maven-resolver-util-1.9.20.jar
        ├── maven-settings-3.9.8.jar
        ├── maven-settings-builder-3.9.8.jar
        ├── maven-shared-utils-3.4.2.jar
        ├── mvnd
        │   ├── jline-native-3.26.2.jar
        │   ├── jline-terminal-3.26.2.jar
        │   ├── jline-terminal-ffm-3.26.2.jar
        │   ├── jline-terminal-jni-3.26.2.jar
        │   ├── mvnd-agent-1.0.1.jar
        │   ├── mvnd-client-1.0.1.jar
        │   ├── mvnd-common-1.0.1.jar
        │   ├── mvnd-daemon-1.0.1.jar
        │   ├── mvnd-helper-agent-1.0.1.jar
        │   ├── mvnd-native-1.0.1.jar
        │   ├── plexus-interactivity-api-1.3.jar
        │   └── takari-smart-builder-0.6.6.jar
        ├── mvnd-logging-1.0.1.jar
        ├── org.eclipse.sisu.inject-0.9.0.M3.jar
        ├── org.eclipse.sisu.inject.license
        ├── org.eclipse.sisu.plexus-0.9.0.M3.jar
        ├── org.eclipse.sisu.plexus.license
        ├── plexus-cipher-2.0.jar
        ├── plexus-cipher.license
        ├── plexus-component-annotations-2.1.0.jar
        ├── plexus-component-annotations.license
        ├── plexus-interpolation-1.27.jar
        ├── plexus-interpolation.license
        ├── plexus-sec-dispatcher-2.0.jar
        ├── plexus-sec-dispatcher.license
        ├── plexus-utils-3.5.1.jar
        ├── plexus-utils.license
        ├── plexus-xml-3.0.0.jar
        ├── plexus-xml.license
        ├── slf4j-api-1.7.36.jar
        ├── slf4j-api.license
        ├── wagon-file-3.5.3.jar
        ├── wagon-http-3.5.3.jar
        ├── wagon-http-shared-3.5.3.jar
        └── wagon-provider-api-3.5.3.jar

17 directories, 115 files

Maven Daemon固有の操䜜を行っおみる

最初にMaven Daemon固有の操䜜を茉せおおきたす。

mvnd --statusで、珟圚起動しおいるMaven Daemonの䞀芧を衚瀺したす。

$ mvnd --status
      ID      PID                   Address   Status    RSS            Last activity  Java home
fc35606d    35163     inet:/127.0.0.1:43263     Idle    98m  2024-07-13T21:10:50.652  /usr/lib/jvm/java-21-openjdk-amd64                                                                        

mvnd --stopで、珟圚起動しおいるMaven Daemonをすべお停止したす。

$ mvnd --stop
Stopping 1 running daemons

mvnd --helpで、ヘルプの衚瀺です。Apache Mavenのヘルプに加えお、Maven Daemon固有の内容が出力されおいたす。

$ mvnd --help

usage: mvnd [options] [<goal(s)>] [<phase(s)>]

Options:
 -am,--also-make                         If project list is specified, also build projects required by the list
 -amd,--also-make-dependents             If project list is specified, also build projects that depend on projects on the list
 -B,--batch-mode                         Run in non-interactive (batch) mode (disables output color)
 -b,--builder <arg>                      The id of the build strategy to use
 -C,--strict-checksums                   Fail the build if checksums don't match
 -c,--lax-checksums                      Warn if checksums don't match
    --color <arg>                        Defines the color mode of the output. Supported are 'auto', 'always', 'never'.
 -cpu,--check-plugin-updates             Ineffective, only kept for backward compatibility
 -D,--define <arg>                       Define a user property
 -e,--errors                             Produce execution error messages
 -emp,--encrypt-master-password <arg>    Encrypt master security password
 -ep,--encrypt-password <arg>            Encrypt server password
 -f,--file <arg>                         Force the use of an alternate POM file (or directory with pom.xml)
 -fae,--fail-at-end                      Only fail the build afterwards; allow all non-impacted builds to continue
 -ff,--fail-fast                         Stop at first failure in reactorized builds
 -fn,--fail-never                        NEVER fail the build, regardless of project result
 -gs,--global-settings <arg>             Alternate path for the global settings file
 -gt,--global-toolchains <arg>           Alternate path for the global toolchains file
 -h,--help                               Display help information
 -itr,--ignore-transitive-repositories   If set, Maven will ignore remote repositories introduced by transitive dependencies.
 -l,--log-file <arg>                     Log file where all build output will go (disables output color)
 -llr,--legacy-local-repository          UNSUPPORTED: Use of this option will make Maven invocation fail.
 -N,--non-recursive                      Do not recurse into sub-projects
 -npr,--no-plugin-registry               Ineffective, only kept for backward compatibility
 -npu,--no-plugin-updates                Ineffective, only kept for backward compatibility
 -nsu,--no-snapshot-updates              Suppress SNAPSHOT updates
 -ntp,--no-transfer-progress             Do not display transfer progress when downloading or uploading
 -o,--offline                            Work offline
 -P,--activate-profiles <arg>            Comma-delimited list of profiles to activate
 -pl,--projects <arg>                    Comma-delimited list of specified reactor projects to build instead of all projects. A project can be specified by [groupId]:artifactId or by its
                                         relative path
 -q,--quiet                              Quiet output - only show errors
 -r,--resume                             Resume reactor from the last failed project, using the resume.properties file in the build directory
    --raw-streams                        Do not decorate output and error streams
 -rf,--resume-from <arg>                 Resume reactor from specified project
 -s,--settings <arg>                     Alternate path for the user settings file
 -t,--toolchains <arg>                   Alternate path for the user toolchains file
 -T,--threads <arg>                      Thread count, for instance 4 (int) or 2C/2.5C (int/float) where C is core multiplied
 -U,--update-snapshots                   Forces a check for missing releases and updated snapshots on remote repositories
 -up,--update-plugins                    Ineffective, only kept for backward compatibility
 -v,--version                            Display version information
 -V,--show-version                       Display version information WITHOUT stopping build
 -X,--debug                              Produce execution debug output


mvnd specific options:
 --completion <string>                  Print the completion for the given shell to stdout. Only --completion bash is supported at this time.
 --diag                                 Terminal diagnosis
 --purge                                Delete log files under the mvnd.registry directory that are older than mvnd.logPurgePeriod
 --status                               Prints the status of daemon instances registered in the registry specified by mvnd.registry
 --stop                                 Stop all daemon instances registered in the registry specified by mvnd.registry
 -f,--file <path>                       The pom or directory to build
 -Djava.home=<path>                     Java home for starting the daemon.
                                        This is a discriminating start parameter.
                                        Env. variable: JAVA_HOME
 -Djdk.java.options=<string>            The JDK_JAVA_OPTIONS option
                                        This is a discriminating start parameter.
                                        Default:
                                        Env. variable: JDK_JAVA_OPTIONS
 -Dmaven.multiModuleProjectDirectory=<path> The root directory of the current multi module Maven project
 -Dmaven.repo.local=<path>              The path to the Maven local repository
                                        This is a discriminating start parameter.
 -Dmaven.settings=<path>;-s,--settings <path> The location of the maven settings file
                                        This is a discriminating start parameter.
 -Dmvnd.buildTime=<boolean>             Log mojos execution time at the end of the build.
 -Dmvnd.builder=<string>;-b,--builder <string> The builder implementation the daemon should use.
                                        Default: smart
 -Dmvnd.cancelConnectTimeout=<duration> Timeout to connect to a cancelled daemon.
                                        Default: 3 seconds
 -Dmvnd.connectTimeout=<duration>       Overall timeout to connect to a daemon.
                                        Default: 10 seconds
 -Dmvnd.coreExtensionsExclude=<string>  Internal option to specify comma separated list of maven extension G:As to exclude (to not load them from .mvn/extensions.xml). This option makes
                                        possible for example that a project that with vanilla Maven would use takari-smart-builder extension, remain buildable with mvnd (where use of this
                                        extension would cause issues). Value is expected as comma separated pairs.
                                        Default: io.takari.maven:takari-smart-builder
 -Dmvnd.daemonStorage=<path>            The directory under which the daemon stores its registry, log files, etc. Default: ${user.home}/.m2/mvnd
                                        Env. variable: MVND_DAEMON_STORAGE
 -Dmvnd.debug=<boolean>                 If true, the daemon will be launched in debug mode with the following JVM argument: -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8000;
                                        otherwise the debug argument is not passed to the daemon.
                                        This is a discriminating start parameter.
                                        Default: false
 -Dmvnd.debug.address=<string>          The tcp address used to launch the debug mode. Defaults to 8000, which is similar to localhost:8000. In order to remote debug from a different
                                        computer, you need to allow remote connections using *:8000 for example. Use a port with a value of 0 to have mvnd to choose one.
                                        This is a discriminating start parameter.
                                        Default: 8000
 -Dmvnd.duplicateDaemonGracePeriod=<duration> Period after which idle duplicate daemons will be shut down. Duplicate daemons are daemons with the same set of discriminating start parameters.
                                        This is a discriminating start parameter.
                                        Default: 10 seconds
 -Dmvnd.enableAssertions=<boolean>      If true, the -ea option will be passed to the daemon; otherwise the -ea option is not passed to the daemon.
                                        This is a discriminating start parameter.
                                        Default: false
 -Dmvnd.expirationCheckDelay=<duration> The daemon will check this often whether it should exit.
                                        This is a discriminating start parameter.
                                        Default: 10 seconds
 -Dmvnd.home=<path>                     The daemon installation directory. The client normally sets this according to where its mvnd executable is located
                                        This is a discriminating start parameter.
                                        Env. variable: MVND_HOME
 -Dmvnd.idleTimeout=<duration>          A time period after which an unused daemon will terminate by itself.
                                        This is a discriminating start parameter.
                                        Default: 3 hours
 -Dmvnd.jvmArgs=<string>                Additional JVM args to pass to the daemon. The content of the .mvn/jvm.config file will prepended (and thus with a lesser priority) to the user
                                        supplied value for this parameter before being used as startup options for the daemon JVM.
                                        This is a discriminating start parameter.
 -Dmvnd.keepAlive=<duration>            If the daemon does not send any message to the client in this period of time, send a keep-alive message so that the client knows that the daemon is
                                        still alive.
                                        This is a discriminating start parameter.
                                        Default: 100 ms
 -Dmvnd.logPurgePeriod=<duration>       Daemon log files older than this value will be removed automatically.
                                        Default: 7 days
 -Dmvnd.maxHeapSize=<memory_size>       The -Xmx value to pass to the daemon. This option takes precedence over options specified in -Dmvnd.jvmArgs.
                                        This is a discriminating start parameter.
 -Dmvnd.maxLostKeepAlive=<integer>      The maximum number of keep alive messages that can be missed by the client before the client considers the daemon to be dead.
                                        Default: 30
 -Dmvnd.minHeapSize=<memory_size>       The -Xms value to pass to the daemon. This option takes precedence over options specified in -Dmvnd.jvmArgs.
                                        This is a discriminating start parameter.
 -Dmvnd.minThreads=<integer>            The minimum number of threads to use when constructing the default -T parameter for the daemon. This value is ignored if the user passes -T, --threads
                                        or -Dmvnd.threads on the command line or if he sets mvnd.threads in ~/.m2/mvnd.properties.
                                        Default: 1
 -Dmvnd.noBuffering=<boolean>           If true the log messages are displayed continuously like with stock Maven; otherwise buffer the messages and output at the end of the build, grouped by
                                        module. Passing -B or --batch-mode on the command line enables this too for the given build.
                                        Default: false
 -Dmvnd.noDaemon=<boolean>              If true, the client and daemon will run in the same JVM that exits when the build is finished; otherwise the client starts/connects to a long living
                                        daemon process. This option is only available with non-native clients and is useful mostly for debugging.
                                        This is a discriminating start parameter.
                                        Default: false
                                        Env. variable: MVND_NO_DAEMON
 -Dmvnd.noModelCache=<boolean>          If true, the daemon will not use its in-memory metadata cache and instead re-read the metadata from the pom.xml files in the local repository. This is
                                        mostly useful for testing purposes.
                                        Default: false
 -Dmvnd.pluginRealmEvictPattern=<string> Pattern that will force eviction of the plugin realms if one of its dependencies matches. The overall pattern is a comma separated list of either: a
                                        glob pattern starting with 'glob:' (the default syntax if no scheme is specified), a regex pattern starting with 'regex:', a maven expression, either
                                        'mvn:[groupId]:[artifactId]:[version]', 'mvn:[groupId]:[artifactId]' or 'mvn:[artifactId]'. This pattern will be evaluated against the full path of
                                        the dependencies, so it is usually desirable to start with 'glob:**/' to support any location of the local repository.
                                        Default:
 -Dmvnd.propertiesPath=<path>           The location of the user supplied mvnd.properties file.
                                        Env. variable: MVND_PROPERTIES_PATH
 -Dmvnd.rawStreams;--raw-streams        Whether or not decorate output and error streams
                                        Default: false
 -Dmvnd.registry=<path>                 The path to the daemon registry. Default: ${mvnd.daemonStorage}/registry.bin
 -Dmvnd.rollingWindowSize=<integer>     The number of log lines to display for each Maven module that is built in parallel. The value can be increased or decreased by pressing + or - key
                                        during the build respectively. This option has no effect with -Dmvnd.noBuffering=true, -B or --batch-mode.
                                        Default: 0
 -Dmvnd.serial;-1,--serial              Use one thread, no log buffering and the default project builder to behave like a standard maven
                                        Default: false
 -Dmvnd.socketConnectTimeout=<duration> Timeout to establish the socket connection.
                                        Default: 1 seconds
 -Dmvnd.socketFamily=<string>           Socket family to use
                                        This is a discriminating start parameter.
                                        Default: inet
 -Dmvnd.threadStackSize=<memory_size>   The -Xss value to pass to the daemon. This option takes precedence over options specified in -Dmvnd.jvmArgs.
                                        This is a discriminating start parameter.
 -Dmvnd.threads=<string>;-T,--threads <string> The number of threads to pass to the daemon; same syntax as Maven's -T/--threads option.
 -Dstyle.color=<string>;--color <string> Whether the output should be styled using ANSI color codes; possible values: auto, always, never
                                        Default: auto
 -Duser.dir=<path>                      The current working directory
 -Duser.home=<path>                     The user home directory

mvnd value types:
 boolean                                true or false; empty string is also interpreted as true - so -Dmvnd.noBuffering is equivalent to -Dmvnd.noBuffering=true
 duration                               An unlabeled whole number of milliseconds or a whole number followed by an optional space and a unit which may be one of the following (in EBNF
                                        notation): d[ay[s]], h[our[s]], m[in[ute[s]]], s[ec[ond[s]]] or m[illi]s[ec[ond[s]]]. Examples: 7 days, 7days, 7d, 100 milliseconds, 100 millis,
                                        100ms, 100
 integer                                A whole number
 memory_size                            An amount of memory as accepted by the -Xm* family of HotSpot JVM options. Examples: 1024m, 2g, 5G
 path                                   A local file system path
 string                                 A string

なお、ヘルプを衚瀺しただけでもMaven Daemonが立ち䞊がるのですが 。

Maven Daemonを䜿っおみる

では、䜿っおみたす。簡単なMavenプロゞェクトを䜜成。

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.littlewings</groupId>
    <artifactId>mvnd-example</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <properties>
        <maven.compiler.release>21</maven.compiler.release>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <version>5.10.3</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
            <version>3.26.3</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

src/main/java/org/littlewings/mvnd/CalcService.java

package org.littlewings.mvnd;

public class CalcService {
    public int plus(int a, int b) {
        return a + b;
    }

    public int minus(int a, int b) {
        return a - b;
    }
}

src/test/java/org/littlewings/mvnd/CalcServiceTest.java

package org.littlewings.mvnd;

import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

class CalcServiceTest {
    @Test
    void testPlus() {
        CalcService calcService = new CalcService();

        assertThat(calcService.plus(3, 5)).isEqualTo(8);
    }

    @Test
    void testMinus() {
        CalcService calcService = new CalcService();

        assertThat(calcService.minus(5, 2)).isEqualTo(3);
    }
}

1床Maven Daemonを止めお

$ mvnd --stop
Stopping 1 running daemons

clean compileで蚈枬。

$ mvnd clean compile

〜省略〜

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.126 s (Wall Clock)
[INFO] Finished at: 2024-07-13T21:35:26+09:00
[INFO] ------------------------------------------------------------------------

2回目。

$ mvnd clean compile

〜省略〜

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.155 s (Wall Clock)
[INFO] Finished at: 2024-07-13T21:35:52+09:00
[INFO] ------------------------------------------------------------------------

ものすごく速くなりたした 。

通垞のMavenず比范しおみたしょう。SDKMANでむンストヌル。

$ sdk install maven

Apache Maven 3.9.8がむンストヌルされたした。

$ mvn --version
Apache Maven 3.9.8 (36645f6c9b5079805ea5009217e36f2cffd34256)
Maven home: $HOME/.sdkman/candidates/maven/current
Java version: 21.0.3, vendor: Ubuntu, runtime: /usr/lib/jvm/java-21-openjdk-amd64
Default locale: ja_JP, platform encoding: UTF-8
OS name: "linux", version: "5.15.0-113-generic", arch: "amd64", family: "unix"

通垞のApache Mavenで実行。

$ mvn clean compile

〜省略〜

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.172 s
[INFO] Finished at: 2024-07-13T21:37:38+09:00
[INFO] ------------------------------------------------------------------------

Maven Daemonの初回実行ず倉わらない速床ですね。

今床はテストを実行しおみたす。Maven Daemonは起動枈みです。

$ mvnd clean test

〜省略〜

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.816 s (Wall Clock)
[INFO] Finished at: 2024-07-13T21:38:39+09:00
[INFO] ------------------------------------------------------------------------

通垞のApache Maven。

$ mvn clean test

〜省略〜

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.369 s
[INFO] Finished at: 2024-07-13T21:39:03+09:00
[INFO] ------------------------------------------------------------------------

だいぶ速くなりたすね。ちょっず驚きたした。

Logbackをビルドしおみる

これで終わりにしおもいいのですが、こんなに小さいプロゞェクトだず恩恵がわかりにくいかもしれたせん。

適圓なOSSのプロゞェクトをビルドしおみようかなずいうこずで、今回はLogbackを遞ぶこずにしたした。

GitHub - qos-ch/logback: The reliable, generic, fast and flexible logging framework for Java.

Logbackをクロヌン。珟時点のバヌゞョンである1.5.6を察象にしたす。

$ git clone https://github.com/qos-ch/logback
$ cd logback
$ git checkout v_1.5.6

Maven Daemonでコンパむル。䟝存ラむブラリヌのダりンロヌドは事前に完了しおいるものずしたす。

$ mvnd clean compile

〜省略〜

[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for Logback-Parent 1.5.6:
[INFO]
[INFO] Logback-Parent ..................................... SUCCESS [  0.002 s]
[INFO] Logback Core Module ................................ SUCCESS [  1.368 s]
[INFO] Logback Core Blackbox Testing ...................... SUCCESS [  0.036 s]
[INFO] Logback Classic Module ............................. SUCCESS [  0.929 s]
[INFO] Logback Classic Blackbox Testing ................... SUCCESS [  0.014 s]
[INFO] Logback Examples Module ............................ SUCCESS [  0.314 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.634 s (Wall Clock)
[INFO] Finished at: 2024-07-13T21:46:21+09:00
[INFO] ------------------------------------------------------------------------

ずころで、Maven Daemonで実行するず途䞭の結果がほずんど衚瀺されず、最埌にたずめお出力されたすね。

Apache Mavenでコンパむル。

$ mvn clean compile

〜省略〜

[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for Logback-Parent 1.5.6:
[INFO]
[INFO] Logback-Parent ..................................... SUCCESS [  0.365 s]
[INFO] Logback Core Module ................................ SUCCESS [  6.015 s]
[INFO] Logback Core Blackbox Testing ...................... SUCCESS [  0.017 s]
[INFO] Logback Classic Module ............................. SUCCESS [  2.032 s]
[INFO] Logback Classic Blackbox Testing ................... SUCCESS [  0.047 s]
[INFO] Logback Examples Module ............................ SUCCESS [  0.674 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  9.541 s
[INFO] Finished at: 2024-07-13T21:46:43+09:00
[INFO] ------------------------------------------------------------------------

テストを実行しおみたしょう。

$ mvnd clean test

〜省略〜

[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for Logback-Parent 1.5.6:
[INFO]
[INFO] Logback-Parent ..................................... SUCCESS [  0.002 s]
[INFO] Logback Core Module ................................ SUCCESS [ 16.484 s]
[INFO] Logback Core Blackbox Testing ...................... SUCCESS [  3.195 s]
[INFO] Logback Classic Module ............................. SUCCESS [ 33.182 s]
[INFO] Logback Classic Blackbox Testing ................... SUCCESS [ 18.106 s]
[INFO] Logback Examples Module ............................ SUCCESS [  0.388 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  01:07 min (Wall Clock)
[INFO] Finished at: 2024-07-13T21:48:44+09:00
[INFO] ------------------------------------------------------------------------

Apache Mavenで実行。

$ mvn clean test

〜省略〜

[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for Logback-Parent 1.5.6:
[INFO]
[INFO] Logback-Parent ..................................... SUCCESS [  0.376 s]
[INFO] Logback Core Module ................................ SUCCESS [ 39.107 s]
[INFO] Logback Core Blackbox Testing ...................... SUCCESS [  3.081 s]
[INFO] Logback Classic Module ............................. SUCCESS [ 35.640 s]
[INFO] Logback Classic Blackbox Testing ................... SUCCESS [ 19.308 s]
[INFO] Logback Examples Module ............................ SUCCESS [  0.579 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  01:38 min
[INFO] Finished at: 2024-07-13T21:51:57+09:00
[INFO] ------------------------------------------------------------------------

バッファリングを切る

Maven Daemonを䜿うず、ふ぀うにApache Mavenを䜿っおいた時ずコン゜ヌルの様子が倉わっお戞惑う気がしたす。これはバッファリング
されおいるからなのですが、無効にする堎合は-Dmvnd.noBuffering=trueを指定したす。

$ mvnd clean test -Dmvnd.noBuffering=true

蚭定をファむルで指定したい堎合はmvnd.propertiesを䜿いたしょう。

bashのコマンド補完を蚭定する

bashのコマンド補完の蚭定もありたす。

mvnd - the Maven Daemon / How to install mvnd / Set up completion

$HOME/.bashrcに、以䞋の内容を远加したしょう。

source [Maven Daemonのむンストヌルディレクトリ]/bin/mvnd-bash-completion.bash

mvnd-bash-completion.bashにパスが通っおいる堎合は、以䞋で远蚘でしょうか。

$ echo "source $(which mvnd-bash-completion.bash)" >> ~/.bashrc

新しいシェルを起動するず補完ができるようになっおいたす。

$ mvnd
clean                     generate-test-resources   package                   pre-integration-test      process-sources           site-deploy
compile                   generate-test-sources     post-clean                pre-site                  process-test-classes      test
deploy                    initialize                post-integration-test     prepare-package           process-test-resources    test-compile
generate-resources        install                   post-site                 process-classes           process-test-sources      validate
generate-sources          integration-test          pre-clean                 process-resources         site                      verify

おわりに

Maven Daemonを詊しおみたした。

確かにだいぶ速床改善されたすね。あずはいろいろなずころで䜿っおみお、特に問題なさそうならこちらに切り替えおもよいかもしれたせん。

様子を芋぀぀、詊しおいこうず思いたす。