What is maven local repository location & how to change it?

By | October 31, 2020

In this post, We will learn about What is maven local repository location & how to change it?

Maven downloads the required artifacts or dependencies (jar files) and other plugins which are configured as part of any project, there must be a commonplace where all such artifacts are placed. This common shared area is called a Repository.

Local Repository:

This repository usually resides in our local machine. Which is cached from the remote/central repository downloads and ready for usage/reuse.

The directory to store all the dependencies in the local machine can be configured in the settings.xml file of the maven directory under the tag <localRepository>

1. Maven’s default local repository location

By default maven’s local repository exists on ‘${user.home}/.m2/repository’. In different operating systems, these paths are resolved to –

We can easily change the local repository path or location to some other location of our choice.

2. Change maven local repository location

Maven is distributed and downloaded as an archive folder. Generally, Software developers download the maven and extract it from their local machine

Once we download the maven, follow the given simple steps to change the maven local repository location to some other path.

  • Navigate to path {M2_HOME}\conf\ where M2_HOME is the maven installation directory.
  • Open file settings.xml file in edit mode in some text editor.
  • Find the tag <localRepository> in settings.xml
  • Update the desired path(e.g C:/kkjavaRepo) in the value of this tag. Save the file.
    setting.xml

    Now if you build your maven project then all the dependencies will be downloaded from the central repository and stored in the above configured local repository path : C:/kkjavaRepo

That’s all about What is maven local repository location & how to change it?
If you have any feedback or suggestion please feel free to drop in below comment box.

Leave a Reply

Your email address will not be published. Required fields are marked *