Maven - Change Local Repository Location

A repository in Maven is used to hold build artifacts and dependencies of varying types. There are strictly only two types of repositories: local and remote.

The local repository refers to a copy on your own machine that is a cache of the remote downloads and also contains the temporary build artifacts that have not yet been released.

When installing Maven, the local repository is located under a default location. The following tutorial shows how you can change the location of this local repository on Windows.

Maven Local Repository

Maven is configured based on a settings.xml file that can be specified at two levels:

User Level: provides configuration for a single user and is typically provided in ${user.home}/.m2/settings.xml.

Global level: provides configuration for all Maven users on a machine (assuming they’re all using the same Maven installation) and it’s typically provided in ${maven.home}/conf/settings.xml.

In this example we will change the local repository location by creating/editing a settings.xml file at user level.

Navigate to [maven_install_dir]/conf and if not already present copy the setting.xml file to the .m2 directory located in the user home directory (in this example the user is 'source4code') as shown below.

Open the copied settings.xml file and add/update the '<localRepository>' element to point to the new location of the local repository. In this example the location is set to C:\source4code\local-repo.