JUnit 5 – When to use ArgumentsSource
February 6, 2024JUnit 5 – When to use CSV Providers
March 10, 2024Introduction
Maven is a solid and most used build automation tool in the Java world. Everyone knows Maven!
It’s present in any type of project and one of the first tools we have contact with while learning Java.
How much do you know about Maven features?
This is why I will show one of the most underrated Maven Configuration features: the maven.config
file.
Motivation
I asked this question on Twitter: How frequently do you use the maven.config
file?
The answer you can see below leads me to think that people don’t know about this Maven feature.
Maven Configurations
The most common Maven Configurations, that you might use at some point are the command line MVN_OPTS
and MVN_ARGS
environment variables for JVM arguments and Maven options, respectively.
But there are more! On the Maven Configurations page, you will see the .mvn
directory section that contains explanations about extensions, JVM config, and the Maven config as the .mvn/maven.config
file.
The Maven Config file
It consists of a file that must be placed in a .mvn
folder in the root project directory. Then the maven.config
file can contain all the parameters you commonly pass as arguments.
Example: When you want to run any command, for example, the test lifecycle, with a quiet output (-q), using 3 threads (-T3) and failing it fast (-fail-fast) you would end up with the following command
mvn -q -T3 -fail-fast test
Be aware of one thing: the configuration in the file is “global” meaning that it will be applied for all the Maven Lifecycles you execute.
For example, let’s assume you have this configuration in your project and you compile, run the tests, and distribute it in a pipeline, the following commands would be used:
- Compilation process:
mvn clean install
- Testing process:
mvn test
- Distribution process:
mvn install
Note that all the commands do not have the -q -T3 -fail-fast
test parameters, but they will be executed anyway because it’s in the .mvn/maven.config
file.
Your .mvn/maven.config
would look like this
-q -T3 -fail-fast test