By default, Maven local repository is defaulted to ${user.home}/.m2/repository
folder :
- Unix/Mac OS X –
~/.m2/repository
- Windows –
C:\Users\{your-username}\.m2\repository
When we compile a Maven project, Maven will download all the project’s dependency and plugin jars into the Maven local repository, save time for next compilation.
1. Find Maven Local Repository
1.1 If the default .m2
is unable to find, maybe someone changed the default path. Issue the following command to find out where is the Maven local repository:
mvn help:evaluate -Dexpression=settings.localRepository
1.2 Example :
Terminal
D:\> mvn help:evaluate -Dexpression=settings.localRepository
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- maven-help-plugin:3.1.0:evaluate (default-cli) @ standalone-pom ---
[INFO] No artifact parameter specified, using 'org.apache.maven:standalone-pom:pom:1' as project.
[INFO]
C:\opt\maven-repository
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.598 s
[INFO] Finished at: 2018-10-24T16:44:18+08:00
[INFO] ------------------------------------------------------------------------
In above output, The Maven local repository is relocated to C:\opt\maven-repository
1.3 Find the MAVEN_HOME
$ mvn --version
Apache Maven 3.6.3
Maven home: /usr/share/maven
Java version: 11.0.15, vendor: Private Build, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.13.0-48-generic", arch: "amd64", family: "unix"
and look for Maven home: in the output , mine is: Maven home: /usr/share/maven
2. Update Maven Local Repository
2.1 Find this file {MAVEN_HOME}\conf\settings.xml
and update the localRepository
.
{MAVEN_HOME}\conf\settings.xml
<settings> <!-- localRepository | The path to the local repository maven will use to store artifacts. | | Default: ~/.m2/repository <localRepository>/path/to/local/repo</localRepository> --> <localRepository>D:/maven_repo</localRepository>
Note
Issue
mvn -version
to find out where is Maven installed.
2.2 Save the file, done, the Maven local repository is now changed to D:/maven_repo
.

3. Force re-download project dependencies
In Maven, you can use Apache Maven Dependency Plugin, goal dependency:purge-local-repository
to remove the project dependencies from the local repository, and re-download it again.
Terminal
$ mvn dependency:purge-local-repository
[INFO] Scanning for projects...
[INFO]
[INFO] --------------< com.favtuts.examples:maven-code-coverage >---------------
[INFO] Building maven-code-coverage 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:purge-local-repository (default-cli) @ maven-code-coverage ---
Downloading from central: https://repo.maven.apache.org/maven2/org/junit/jupiter/junit-jupiter-engine/5.3.1/junit-jupiter-engine-5.3.1.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/junit/jupiter/junit-jupiter-engine/5.3.1/junit-jupiter-engine-5.3.1.pom (2.4 kB at 2.1 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/apiguardian/apiguardian-api/1.0.0/apiguardian-api-1.0.0.pom
//...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.086 s
[INFO] Finished at: 2018-11-20T15:22:28+08:00
[INFO] ------------------------------------------------------------------------