Main Tutorials

Where is Maven local repository?

By default, Maven local repository is defaulted to ${user.home}/.m2/repository folder :

  1. Unix/Mac OS X – ~/.m2/repository
  2. 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

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.

References

  1. Maven Central Repository
  2. Introduction to Repositories

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
30 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
martin
8 years ago

Hi,

All your tutorials are very well explained, in detail and in step by step way.
You are doing a wonderful job!

cycarrenol
3 years ago

Thanks!

vinayak patil
4 years ago

while creating a MAVEN project in eclipse getting below error.
Could not resolve archetype org.apache.maven.archetypes:maven-archetype-webapp:1.0 from any of the configured repositories.

pavi
5 years ago

after Finding Maven Local Repository do I need to update

ROGER DELOY PACK
5 years ago

settings.xml not setting.xml

Jason Robinson
8 years ago

I have been looking for a multiple local repository fall back solution. In otherwords, if the group intranet server (hosting the maven repo) isn’t available, then check the local (C:/) repo and if you can’t find something there, go to maven central.

Ash Trick
9 years ago

quick question, there is a repository.xml in the local repository. What is that used for?

Nanuk
9 years ago

As I understand jars are downloaded by Maven automatically , when we adding dependency in pom . But from where maven download jars ?

Ali
9 years ago

Short , Simple and Best description…!Thanks

Amol Manthalkar
10 years ago

Hi,

It would be easy to proceed through the tutorial if we can have next and previous button at the end of topic. 🙂

Amal
10 years ago

Hi i’m using netbeans 7.3 and i can’t find maven repository browser in (window->other ).

Jason Robinson
8 years ago
Reply to  Amal

I’m using netbeans as well. Don’t use Netbeans to try to browse a repository. Maven is meant to run OUTSIDE of an IDE.

Al Mobe
10 years ago

You just missed about the eclipse update for this solution. I found a best practice to change maven local repository here
http://jroadie.com/maven/how-to-change-maven-local-repository/

elzakaria
10 years ago

Thanks a lot, just curious, when you said

Find {M2_HOME}\conf\setting.xml, update localRepository to something else.
You wanted to say

Find {MAVEN_HOME}\conf\setting.xml, update localRepository to something else.

Or it is correct?
Thanks 🙂

RoarLion
9 years ago
Reply to  elzakaria

both are same M2_HOME= MAVEN_HOME

Rajesh
10 years ago
Reply to  elzakaria

Exactly !!!

Yoesoff
10 years ago

simple and helpful, thanks

Oskar
11 years ago

Hi there
I’m quite new to maven and I’ve been trying to rotate the location of the settings.xml file, as I need it under version control, thus in a specific directory.
So far I tried “export MAVEN_OPTS=-Dorg.apache.maven.user-settings=/path/to/directory/settings.xml”
But unfortunatly that doesn’t work. It tried this because it works with switching the local repo with “export MAVEN_OPTS=-Dmaven.local.repo=/path/to/repo”.
Does anybody know how this could be accompished without using “mvn -s /path/to/directory/settings.xml someplugin:someGoal” ? Any hints, tips, tricks would be great,…. google could not really solve this… 🙁

Cheers Oskar

Natwar Sharma
11 years ago

Short and sweet.Thanks alot man!!

Satya Marrapu
11 years ago

Hi yong i’m doing what you were specify in tutorial, but i’m getting BUILD-ERROR.

How to resolve that, plz help me

sumit das
11 years ago

Thanks. Simple and clear description.

Keep up the good work.

Younus
11 years ago

Still am not getting the repo folder

RoarLion
9 years ago
Reply to  Younus

Hi younus,

may be few reasons.

And check for the maven home environment variable has set . if not do it correctly.
check whether you have any other maven installation in your machine. after you setting the

environment and path variables restart the machine.
for my case I had a previous maven installation and repo folder created according to that setting file local repository location. (although when I type mvn –version it shown the current maven directory ).
Then I restarted and now working fine.

RoarLion
9 years ago
Reply to  Younus

go to the the C:Documents and SettingsYour User folder .m2

Reddy
11 years ago

Hi,
im new to maven

Help me
how create a .m2 directory in c:users/directory

Rafa
11 years ago

Is there a typo in the text for “settings.xml”? I think the line:

<localRepository>D:/maven_repo</localRepository>

should read:

<localRepository>D:/maven/repo</localRepository>

based on the directory structure you displayed in the image.

William
10 years ago
Reply to  Rafa

I was even second guessing whether Maven translated _ to / or something, until I read your comment.

marcos
11 years ago

Short and clean. Thanks a lot!!

Nagesh
11 years ago

Very info.
I’m follower of your blog/sites of Java. Thanks a lot for your efforts to make my life easy.