Maven local repository location & how to change it?

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.

setting.xml
 
  <!-- 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.

After change, check it.
mvn help:evaluate -Dexpression=settings.localRepository | grep -v '\[INFO\]'