In a previous blog we learned about setting default JVM options when we run Maven commands.
We can also set default Maven options that we want to apply each time we run a Maven command.
All options can be defined in the file maven.config
in a .mvn
directory in the root of our project.
Each option must be defined on a new line.
This directory and file can be added to our source control so that all users that have access to the repository will use the same Maven options.
In the following example we have a file .mvn/maven.config
where we want to show Maven version information for each run, use a thread per CPU core, always try to build all modules and fail at the end if there are failures and finally we set user properties that are used by the Maven compile plugin:
--show-version --threads=1C --fail-at-end -Dmaven.compiler.source=17 -Dmaven.compiler.target=17 -Dencoding=UTF-8
With the above configuration we can see that options are applied when we run the verify
command:
$ mvn verify ... Apache Maven 3.9.1 (2e178502fcdbffc201671fb2537d0cb4b4cc58f8) Maven home: /Users/mrhaki/.sdkman/candidates/maven/current Java version: 19.0.2, vendor: Eclipse Adoptium, runtime: /Users/mrhaki/.sdkman/candidates/java/19.0.2-tem Default locale: en_NL, platform encoding: UTF-8 OS name: "mac os x", version: "13.2.1", arch: "x86_64", family: "mac" ... [INFO] Scanning for projects... [INFO] [INFO] Using the MultiThreadedBuilder implementation with a thread count of 12 ... $
Written with Maven 3.9.1.