Thursday, May 18, 2017

Customizing external maven settings

Maven configuration happens on several levels. Mostly the configuration is just the project pom.xml. There are several things related to the environment, which cannot be defined in the pom.xml. Such additional settings may be provided with the external file.

The default external settings


The are two default levels of external settings: global (installation) configuration and user configuration.
The default location of the global settings file is $m2_home/settings.xml, where m2_home is the maven installation directory.
The default location of the user settings file is $user/.m2/settings.xml, where user is the user home directory.

The default external settings is used on call of any maven command and for all projects. If there is no external settings on either of global or user levels, maven uses the default values.

For details about available settings options use the settings reference and the configuration guide.

Properties overriding


The user settings property is effective only if such property is empty in the global settings.
The user settings property value is ignored, if there is a value defined in the global settings.

Custom external settings


Both global and user external settings may be provided as a maven argument. Such settings overrides the appropriate default settings.

The option -gs is for the global settings. For example:
 mvn clean install -gs abc-settings.xml
Since the command receives the global settings argument, maven will use the provided settings first and then will look for the default user settings.

The option -s is for the user settings. For example:
 mvn clean install -s abc-settings.xml
Since the command receives the user settings argument, maven will look for the default global settings first and then will use the additional properties from the provided external settings.

Maven external setting in eclipse


In eclipse maven external setting is set as following:

1. Go to Window->Preferences->Maven-> User settings
2. In the dialog define the global settings file and/or the user settings file. Each file will be used instead of the appropriate default settings.

No comments :

About the author

My Photo
I trust only simple code and believe that code should be handsome. This is not a matter of technology, but professional approach, consolidated after years of software development. I enjoy to cause things working and feel very happy, when I manage to solve a problem.
Back to Top