How to change local Maven repository location

When you use Maven as build tool for your projects, Maven maintains a local repository for jar files, plugins and other files which has been used in your projects, Maven refers the jar file and other files for project while building.

You can see the path of maven repository inside user directory of window, Maven creates a folder named ‘.m2′, inside ‘.m2′ you will find one more folder named as ‘repository’, You can find all the jar files inside this repository folder which are used for your projects.

Maven will first look for all the dependencies jar files inside local repository. If Maven found inside local repository, it will use the same jar files for building the project. If Maven did not find any of dependency jar file inside local repository, It will download the jar file from its own central repository which is, and store them in local repository, this feature makes Maven as Powerful build tool, you no longer need to search for different jar files for your project.

Sometimes you don’t want the default location, You can change this local repository as you want. To change the Maven local repository you need to go Maven home directory, where you will find one folder named as ‘conf’, inside this folder you will have one settings.xml file, Open settings.xml file in any text editor.

The settings.xml file is the configuration file for Maven. Search for ‘localRepository’ tag, by default it is commented, uncomment it and put your local repository path as you want. Below the example code.


Your new Maven local repository is now changed to your specified path, now onward all the future project’s dependency libraries or related files will be downloaded into this folder. You can copy the content of old repository inside new repository so Maven can find already downloaded files in local repo.