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>
  <!-- any type of slashes works -->
  <localRepository>D:/mavenrepository</localRepository>
</settings>

That’s it!

Update 06/12/2011: fixed typo in name of tag

About Eric Lefevre-Ardant

Independent technical consultant.
This entry was posted in java, maven. Bookmark the permalink.

23 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

  16. C P Joshi says:

    Thanks a lot! It worked and saved lot of hours that otherwise might have spent in trial and error.

  17. Sweep says:

    Christian,

    Thanks for the -Dmaven.repo.local= tip!

  18. Radek says:

    Use c:\DOCUME~1\rmensik\.m2\repository instead of Document and settings

  19. Gayathri says:

    If i want my maven project to point to the repository of some other machine. how can i do it. say for ex. there is an internal server machine for my project, i have to point to the server machine’s repository instead of the downloading the files from central repo . how can i give it in tag of my POM file?

  20. You’ll have to use whatever mechanism your OS provides to access remote directories. Assuming that you are under Windows, this means mapping the remote folder to some unused drive letter, such as Z:. The rest of the procedure would then be the same as what is described here.

    If that does not work on your system, you should consider installing a Maven proxy on your remote machine, such as Nexus or Artifactory. In fact, that would be the recommended way of doing it.

  21. Gayathri says:

    The first approach works good. Thanks:)

  22. On my computer, it’s actually c:\users\clintjcl\.m2\

    Windows 7

Comments are closed.