Task 4: Configuring Maven

Naturally, Maven works out of the box with zero configuration.

Maven will create the directory ~/.m2 the first time you run the mvn command. This directory is used to store a number of user-specific files.

The first time Maven needs to download a plugin and or dependency it will create the directory ~/.m2/repository and store whatever it ends up downloading there. Each plugin or dependency is stored in a directory that follows the groupId/artifactId/version properties of the release that's required. You don't need to worry about the structure because Maven will handle downloading, storing and finding the plugins and dependencies it needs on your behalf. The artifacts are stored here for the next time a command you run needs them.

Maven can be customized per-user by editing the file ~/.m2/settings.xml. Your settings file lets you configure Maven with custom authentication information, custom repositories and other settings. The files doesn't exist by default, so you will need to create it yourself. We will explore a number of these configuration options as they become relevant in future chapters. Maven provides a default version of the settings file with helpful comments in $M2_HOME/conf/settings.xml.

Although you shouldn't need to change it, you can alter the location of your local repository by using the <localRepository> element with the path you'd prefer to use.

Create a base settings.xml

Edit ~/.m2/settings.xml and add the following:

<settings>
</settings>

Change the location of your local repository

Put the following in ~/.m2/settings.xml:

<settings>
  <localRepository>
    /Users/brian/maven/repositories/maven2/
  </localRepository>
</settings>