How do I set the location of my local Maven repository?
Author: Deron Eriksson
Description: This tutorial describes how to change the location of your local maven repository.
Tutorial created using: Windows Vista || JDK 1.6.0_04


The location of your mavenSW local repository can be changed by adding or modifying a localRepository element to your settings.xml file. The default settings.xml file contains the following entry, describing this.

From settings.xml

  <!-- localRepository
   | The path to the local repository maven will use to store artifacts.
   |
   | Default: ~/.m2/repository
  <localRepository>/path/to/local/repo</localRepository>
  -->

I'd like my local repository to be located at C:\dev\m2repo, so I'll add the following entry to settings.xml:

<localRepository>/dev/m2repo</localRepository>

Now let's test it and see if it works. To do this, I'll run a maven command at the command prompt. I'll do a "maven clean". This command will fail since I'm not running it in a directory with a pom.xml file, but that's fine. We're just running a maven command which requires the download of some files (including a jarW file) from the central maven repository to our local maven repository.

'maven clean' at command prompt

After running this command, we can check and make sure that the localRepository setting worked. If we open a Windows Explorer window and navigate to our C:\dev directory, we can see that an m2repo directory has been created. If we inspect the contents of m2repo, we can see that it indeed contains maven repository contents, as expected.

files have been downloaded to new local maven repository