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
Thanks a ton. I was looking for this information for quite some time. You saved my day.
Thank you, very helpful.
Also at least in maven 2.0.9 its
D:\mavenrepository
notice the capitol R in repository
Lol alright well its
>localRepository<C:\Tools\mavenRepo\repository<//localRepository>
Sweet; just what I was looking for. :)
Pingback: Ernesto’s Miscellanea » Blog Archive » Maven tips
At least I found this info. Thanks!
Thanks for the tip, Eric!
If you do not want to change your settings.xml, you can simply pass ‘-Dmaven.repo.local=’ to your mvn call
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!!!!!
@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.
Over 2 years later, your post is still helping people. Thanks for taking the time to post this tip!
It’s with a capital “R” http://maven.apache.org/ref/2.0.8/maven-settings/settings.html
Tranks a lot!
Thank you!
Thanks a lot!
Right the tip im searching for.
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
Thanks a lot! It worked and saved lot of hours that otherwise might have spent in trial and error.
Christian,
Thanks for the -Dmaven.repo.local= tip!
Use c:\DOCUME~1\rmensik\.m2\repository instead of Document and settings
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?
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.
The first approach works good. Thanks:)
On my computer, it’s actually c:\users\clintjcl\.m2\
Windows 7