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 2 3 4 5 6 |
<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>C:\Users\Kishan Kumar\.m2\</localRepository> </settings> |
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 –
1 2 3 4 |
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 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
123456789101112131415<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| THis is the path where maven will use to store artifacts.|| Default: ${user.home}/.m2/repository --><localRepository>C:/kkjavaRepo</localRepository>......</settings>
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.