Configuring Maven

Maven configuration occurs at 3 levels:

  • Project - most static configuration occurs in pom.xml
  • Installation - this is configuration added once for a Maven installation
  • User - this is configuration specific to a particular user

The separation is quite clear - the project defines information that applies to the project, no matter who is building it, while the others both define settings for the current environment.

Note: the installation and user configuration cannot be used to add shared project information - for example, setting <organization> or <distributionManagement> company-wide.

For this, you should have your projects inherit from a company-wide parent pom.xml .

You can specify your user configuration in ${user.home}/.m2/settings.xml . A full reference to the configuration file is available. This section will show how to make some common configurations. Note that the file is not required - defaults will be used if it is not found.

Configuring your Local Repository

The location of your local repository can be changed in your user configuration. The default value is ${user.home}/.m2/repository/ .

<settings>
  ...
  <localRepository>/path/to/local/repo/</localRepository>
  ...
</settings>

Note: The local repository must be an absolute path.

Configuring a Proxy

Proxy configuration can also be specified in the settings file.

For more information, see the Guide to using a Proxy .

Security and Deployment Settings

Repositories to deploy to are defined in a project in the <distributionManagement> section. However, you cannot put your username, password, or other security settings in that project. For that reason, you should add a server definition to your own settings with an id that matches that of the deployment repository in the project.

In addition, some repositories may require authorization to download from, so the corresponding settings can be specified in a server element in the same way.

Which settings are required will depend on the type of repository you are deploying to. As of the first release, only SCP deployments and file deployments are supported by default, so only the following SCP configuration is needed:

<settings>
  ...
  <servers>
    <server>
      <id>repo1</id>
      <username>repouser</username>
      <!-- other optional elements:
        <password>my_login_password</password>
        <privateKey>/path/to/identity</privateKey> (default is ~/.ssh/id_dsa)
        <passphrase>my_key_passphrase</passphrase>
      -->
    </server>
  ...
  </servers>
  ...
</settings>

Using Mirrors for Repositories

Repositories can be declared inside a project, which means that if you have your own custom repositories, those sharing your project easily get the right settings out of the box. However, you may want to use an alternative mirror for a particular repository without changing the project files.

Some reasons to use a mirror are:

  • There is a synchronized mirror on the internet that is geographically closer and faster
  • You want to replace a particular repository with your own internal repository which you have greater control over
  • You want to run maven-proxy to provide a local cache to a mirror and need to use its URL instead

To configure a mirror of a given repository, you provide it in your settings file, giving the new repository its own id and url , and specify the mirrorOf setting that is the ID of the repository you are using a mirror of. For example, the id of the main Maven repository included by default is central , so to use an Australian mirror, you would configure the following:

<settings>
  ...
  <mirrors>
   <mirror>
      <id>planetmirror</id>
      <name>Australian Mirror of http://repo1.maven.org/maven2/</name>
      <url>http://public.planetmirror.com/maven2/</url>
      <mirrorOf>central</mirrorOf>
    </mirror>
  ...
  </mirrors>
  ...
</settings>

More info about mirrors is available in the Guide to Mirror Settings .

Profiles

Repository configuration can also be put into a profile. You can have multiple profiles, with one set to active so that you can easily switch environments. Read more about profiles in Introduction to Build Profiles .