Maven settings

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.

Tip

Remember that by ~ we mean the user home, which is usually located under /home/<username> for Linux users and under C:Users<username> for Windows users.

In the Maven settings, we can specify some properties and flags, as follows:

  • The path of the local repository. This is ~/.m2/repository by default.
  • The offline flag prevents Maven from connecting to remote repositories (useful in case of network problems).
  • The <proxies> element allows us to configure proxies used to connect to the network.
  • The <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.
  • The <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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset