Apache Maven – Changing default Maven repository location in Windows 7 OS

In this article, we will try to change the default local maven repository location to some preferred location in windows environment

1. Local Maven repository

  • It is where all your dependencies like dependent jars and any associated plugins used in the projects gets downloaded and its location default to C:\Users\<user_name>\.m2\repository
  • Note: Sometime it changes, depending upon windows installation
  • Default Maven settings.xml (MAVEN_HOME\conf\settings.xml)
<!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ${user.home}/.m2/repository
<localRepository>/path/to/local/repo</localRepository>
-->

Q) How to update or modify or change this default location ?

  • Go to the location –> MAVEN_HOME –> conf –> settings.xml
  • Modify <localRepository> element to some user-defined location with absolute path

2. Update location with absolute path

<localRepository>D:\M2_HOME\.m2\repository</localRepository>

New maven settings.xml

<!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ${user.home}/.m2/repository
<localRepository>/path/to/local/repo</localRepository>
-->
<localRepository>D:\M2_HOME\.m2\repository</localRepository>

Save it !! that’s done

New local maven repository

1_Apache-Maven-Repo-location_m2_repository

Useful Eclipse IDE shortcuts :

Related Articles:

Happy Coding !!
Happy Leaening !!

Apache Maven - Local, Central and Remote Repositories
Apache Maven - pom.xml explanation