Home  >  Maven

Change Maven Local Repository Location

By Arvind Rai, May 19, 2021
To change Maven local repository we need to change the value of <localRepository> element in settings.xml file.
Default value of <localRepository> is ${user.home}/.m2/repository.


The settings.xml file can be found in two locations.
1. ${maven.home}/conf/settings.xml
2. ${user.home}/.m2/settings.xml

The ${maven.home} is Maven installation home and ${user.home} is location of user specific directory. Find the location of settings.xml for ${user.home} OS wise.
1. Windows
2. Linux
3. Mac

The settings.xml file located in ${maven.home} is called global setting and settings.xml file located in ${user.home} is called user specific setting. If both file exists, their contents are merged and user specific settings.xml located in ${user.home} will be dominant.


The location of local repository of a build system are configured using <localRepository> element in settings.xml 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 https://maven.apache.org/xsd/settings-1.0.0.xsd">

Default value of <localRepository> is ${user.home}/.m2/repository. We can change the location of local repository using <localRepository> element by passing our local repository location.

Purging Local Repository Dependencies

Use following command to purge local repository.
mvn dependency:purge-local-repository 
The default behavior of the above command is first resolve the entire dependency tree then delete the contents from the local repository and then re-resolve the dependencies.
By default, the plugin operates on all transitive dependencies. Plugin may download the certain missing dependencies to gather the full dependency information before beginning the purge process. We can avoid the pre-download step using following command.
mvn dependency:purge-local-repository -DactTransitively=false 


Configuring Maven
Settings Reference

©2022 concretepage.com | Privacy Policy | Contact Us