Maven – Local Repository Location

In this Maven tutorial, we will know the default location of Maven repository and how to configure a custom location.

Maven has the following types of repositories:

  • Local: This is the repository in our computer.
  • Remote: This is the repository in Internet from where the required Maven files get downloaded.
  • Mirrors: These are repository managers managed by the organizations which want to control the artifact versions allowed in their development teams. Nexus and Artifactory are examples of these mirror repositories.

Maven local repository is a folder in our computer where Maven stores the dependencies in download from the remote repositories.

1. Default Location of Maven Local Repository

Once we have installed Maven, by default, Maven’s local repository is configured to be ‘${user.home}/.m2/repository‘.

In different operating systems, these paths 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 may want to change this location to another path for various reasons. For example, we may want to save storage space in C:\ and store downloaded files in another drive.

2. Change Local Repository Location

Maven is downloaded and extracted as an archive file. Generally, we download the Maven and extract it in their computer.

After downloading the Maven, follow the given simple steps to change the 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>

We have now successfully changed the maven local repository path.

We can verify by updating any pom.xml file and all downloaded dependencies in the new location.

Maven local repository path
Maven local repository path

Note that if there are existing jar files and pom files stored in the previous local repository location, they will not be moved. We need to move them or remove them manually.

3. Change Local Repository Location in Eclipse

These days, IDEs also come with inbuilt Maven support and we only need to install Maven if we are making the project builds from Console.

Each IDE has a separate process to change the local repository path and that you can read its official documentation.

For example in Eclipse and STS (Spring Tools Suite), we can change the local repository path in the following location: Windows -> Pfreferences -> Maven -> User Settings

Here you can give the path of settings.xml file where we have configured the folder location of the local repository.

Happy Learning !!

Was this post helpful?

Join 7000+ Awesome Developers

Get the latest updates from industry, awesome resources, blog updates and much more.

* We do not spam !!

7 thoughts on “Maven – Local Repository Location”

  1. 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/

    Reply
  2. Which tag needs to be opened? Tag name has not been specified in existing maven installation case. Kindly specify it.

    Reply
      • where have you corrected …….? I m not getting right way to find the settings.xml file in repository plz………make it clear ?

        thank you.

        Reply
        • 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.

          Reply

Leave a Comment

HowToDoInJava

A blog about Java and related technologies, the best practices, algorithms, and interview questions.