Changing maven local repository

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!

About Eric Lefevre-Ardant

Member of the Algodeal Tech Team.
This entry was posted in java, maven. Bookmark the permalink.

16 Responses to Changing maven local repository

  1. partha says:

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

  2. nthomas says:

    Thank you, very helpful.

    Also at least in maven 2.0.9 its

    D:\mavenrepository

    notice the capitol R in repository

  3. nthomas says:

    Lol alright well its

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

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

  5. Pingback: Ernesto’s Miscellanea » Blog Archive » Maven tips

  6. Den says:

    At least I found this info. Thanks!

  7. Beel says:

    Thanks for the tip, Eric!

  8. Christian says:

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

  9. sunes says:

    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!!!!!

  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.

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

  12. altiro says:

    Tranks a lot!

  13. Katarina says:

    Thank you!

  14. Alex says:

    Thanks a lot!
    Right the tip im searching for.

  15. 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

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>