The /conf
folder of the Maven installation directory contains a settings.xml
file that can be edited to customize some configuration properties used during our builds. This file is also referred to as the Maven Global Settings
file. We can override these settings in a settings.xml
file that we can create in the ~/.m2/
folder. While the Global Settings file is used by all the users of the same machine, the file under ~/.m2/
is used only by the local user, and it is called the Maven Local Settings file.
In the Maven settings, we can specify some properties and flags, as follows:
~/.m2/repository
by default.offline
flag prevents Maven from connecting to remote repositories (useful in case of network problems).<proxies>
element allows us to configure proxies used to connect to the network.<servers>
element allows us to specify the credentials of the Maven repositories to which we want to deploy our artifacts. We'll speak about deploying our projects to remote repositories in Chapter 5, Continuous Integration and Delivery with Maven.<profiles>
element is similar to the one that we can specify in our POMs. We'll speak of Maven profiles in Chapter 4, Managing the Code. This element should be used very carefully because a project should not depend too much on settings specified outside of its POM.For example, it can be convenient to share a local repository between all the users of the same machine. This can be done specifying a path for the local repository in the Maven Global Settings file, which is accessible by all the users.
In order to see the result of the merging between the local and Global Settings, we can use the Maven Help Plugin, as follows:
$ mvn help:effective-settings
This goal is analogous to the effective-pom
goal of the same plugin. We can find a complete reference of the Maven settings on the Maven site at http://maven.apache.org/settings.html.