Eric Lefevre-Ardant on Java & Agile

February 21, 2007

Changing maven local repository

Filed under: java, maven — Eric Lefevre-Ardant @ 11:49 am

This is something that is not well documented on the web, though it is quite clearly in the default settings.xml file provided with the default Maven installation.

The default repository used by Maven 2 to store the various artifacts is <user_home>/.m2/repository. Under Windows, that translates to C:\Documents and Settings\<user>\.m2\repository.
On my client site, the size of the user home directory is severely restricted, presumably because it is being backed up. So, how do you change this value? Easy, once you know.

You need to have a settings.xml file, either in the <user_home>/.m2 directory, or in the <maven installation>/conf directory (make sure you keep a copy of the existing one). Add a new <localrepository> tag. On my machine, it looks like that:

<settings>  ...

<localrepository>D:/mavenrepository</localrepository> <!-- any type of slashes works -->

...

</settings>

That’s it!

16 Comments »

  1. Thanks a ton. I was looking for this information for quite some time. You saved my day.

    Comment by partha — April 3, 2008 @ 11:03 pm

  2. Thank you, very helpful.

    Also at least in maven 2.0.9 its

    D:\mavenrepository

    notice the capitol R in repository

    Comment by nthomas — April 18, 2008 @ 8:14 pm

  3. Lol alright well its

    &gtlocalRepository&ltC:\Tools\mavenRepo\repository&lt//localRepository&gt

    Comment by nthomas — April 18, 2008 @ 8:16 pm

  4. Sweet; just what I was looking for. :)

    Comment by Michael Laccetti — September 8, 2008 @ 6:02 pm

  5. [...] You’ll need this reference for the user-specific configuration of Maven and if you’re looking into moving your local maven repository, you need this blog entry. [...]

    Pingback by Ernesto’s Miscellanea » Blog Archive » Maven tips — October 20, 2008 @ 9:25 am

  6. At least I found this info. Thanks!

    Comment by Den — October 28, 2008 @ 9:39 am

  7. Thanks for the tip, Eric!

    Comment by Beel — March 8, 2009 @ 7:56 pm

  8. If you do not want to change your settings.xml, you can simply pass ‘-Dmaven.repo.local=’ to your mvn call

    Comment by Christian — March 24, 2009 @ 11:12 am

  9. Hi! I am trying to change my local repository of maven, but I am using ant too, so I can’t find where to do it: in the fetch.xml (from ant) file, or in the settings.xml file. Of course i tried it changing the settings.xml, but it didn’t work, so now i am trying it in the fetch.xml and get-m2.xml of ant, but i haven’t got nothing yet…
    any idea??????

    thanx!!!!!

    Comment by sunes — April 24, 2009 @ 12:23 pm

  10. @sunes What you are trying to do is not clear to me… are you trying to have a common classpath for Maven and for Ant scripts embedded in Maven? I think you can obtain the classpath for the compile scope, though I’m not sure how.
    If you have both Maven and (separate) Ant scripts, I guess you need to point to the Maven repository in two places.

    Comment by Eric Lefevre-Ardant — April 24, 2009 @ 1:51 pm

  11. Over 2 years later, your post is still helping people. Thanks for taking the time to post this tip!

    Comment by Frederic Daoud — April 30, 2009 @ 6:37 pm

  12. It’s with a capital “R” http://maven.apache.org/ref/2.0.8/maven-settings/settings.html

    Comment by Heiko — July 6, 2009 @ 3:53 pm

  13. Tranks a lot!

    Comment by altiro — January 11, 2010 @ 10:00 pm

  14. Thank you!

    Comment by Katarina — March 12, 2010 @ 4:38 pm

  15. Thanks a lot!
    Right the tip im searching for.

    Comment by Alex — April 7, 2010 @ 10:15 pm

  16. Thanks for that! You’re right, I was also looking for this on the Maven2 project user guide at http://maven.apache.org/guides/ and couldn’t find it..doesn’t seem to be there. This post came in handy! Cheers

    Comment by Tulio Domingos — May 2, 2010 @ 1:49 pm

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress