Mvn Config

Maven per-project settings

As seen on SKDMan Install and SDKMan Advance Config, often a project has specific requirements.

As a developer, if I wrote more than two times the same command, I try to find a way to automate that process.

Talking about Maven, in a development environment, where we always have to pass the same parameters. In this case the “Maven common configs” file comes to help.

Create .mvn folder and maven.config file

In your root project directory create another directory named “.mvn” .

mkdir .mvn

Crate a brand-new file maven.config

touch .mvn/maven.config

Set a specific settings.xml

For example, if you want set a per-project specific settings.xml file

-s /home/<userName>/.m2/settings_custom.xml

Set a specific repository dir

…per-project specific repository dir file. Very useful if your project points to a dedicated Nexus for his dependencies.

-Dmaven.repo.local=/home/<userName>/.m2/repository_custom

Set a default externals env variables

-DenvVariable=local -DanotherProperties.name=local.properties

Put all together

-s /home/<userName>/.m2/settings_custom.xml -Dmaven.repo.local=/home/<userName>/.m2/repository_custom -DenvVariable=local -DanotherProperties.name=local.properties 

Test it

Try to run a simply mvn clean and see all the default arguments passed to the mvn command.

See you for the next Dev Tips!

Enjoy, Djacomo

Disclaimer: I’m Italian, so sorry for my bad English!