In this tutorial, learn to change maven local repository location. Maven is build and dependency management tool. It downloads required project dependencies to our local system and include them to project compilation or run-time as defined.
1. Maven’s default local repository location
By default maven’s local repository exist on ‘${user.home}/.m2/repository’. In different operating systems, these path are resolved to –
Windows 7: C:/Documents and Settings/<username>/.m2/repository Windows 10: C:/Users/<username>/.m2/repository Linux: /home/<username>/.m2/repository Mac: /Users/<username>/.m2/repository
We can change local repository location to some other location of our choice.
2. Change maven local repository location
Maven is distributed as archive folder. Generally, developers download the maven and extract it their workstation.
After you have downloaded the maven, follow given simple steps to change maven local repository location to some other path.
- Navigate to path {M2_HOME}\conf\ where
M2_HOME
is maven installation folder. - Open file settings.xml in edit mode in some text editor.
- Fine the tag <localRepository>
- Update the desired path in value of this tag. Save the file.
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> <!-- localRepository | The path to the local repository maven will use to store artifacts. | | Default: ${user.home}/.m2/repository --> <localRepository>E:/devsetup/M2</localRepository> ... ... </settings>
- Congratulations, You are done.
Maven local repository path
Happy Learning !!
Durgesh kumar
thank u so much sir
Mauro
I had modified the settings.xml in {M2_HOME}\conf\ but maven ignored it, to resolve that just copy that settings.xml to {user.home}/.m2/
Ashish Bhargava
Which tag needs to be opened? Tag name has not been specified in existing maven installation case. Kindly specify it.
Lokesh Gupta
Thanks for pointing it out. I corrected the post content. It was a formatting error.
kaushal
where have you corrected …….? I m not getting right way to find the settings.xml file in repository plz………make it clear ?
thank you.
Lokesh Gupta
The content is updated. I again verified it. It you are installing it first time, OR you don’t have the settings.xml file in it’s location then create a new file with name “settings.xml”. Location of file will be C:/Documents and Settings/<current username>/.m2
Current username is your windows username e.g. admin.
Stanislav
Thank you!
Those recommendations was helped me.