How to find local Maven repository?

Where is my local maven repository and how do I find? By local maven repository, I mean the folder where Maven installs all local dependencies.

  1. Maven Local Repository
    1. Unable to find local Maven repository in the default location?
    2. How to change the location of local Maven repository?

Maven Local Repository

The maven local repository is a directory on your machine where Maven downloads and caches dependencies (JARs) and stores temporary build artifacts when you build a Maven project.

By default, the local repository lives under the ${HOME}/.m2/ folder or simply ~/.m2

  • macOS: ~/.m2 or /Users/<USER_NAME>/.m2/
  • Windows: C:\Users\<USER_NAME>\.m2

Unable to find local Maven repository in the default location?

If you cannot find the local repository under ~/.m2 folder, it’s probably configured in a different location (usually by an admin.) Run the following command to get the location of the repo:

mvn help:evaluate -Dexpression=settings.localRepository

If this is successful, you’ll see something like this in the output

<truncated>
[INFO] 
/Users/mike/.m2/repository
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
<truncated>

How to change the location of local Maven repository?

The path of the local repo is specified in settings.xml file, which is located in the Maven ~/.m2 directory. You can override the path to local repository by adding the following:

<settings>
    <localRepository>/some_path/.m2_new</localRepository>
    ...
</settings>

If you apply the change above, Maven will download artifacts in the /some_path/.m2_new repository.

Alternatively, you can also pass the path of the repository on the command line:

mvn -Dmaven.repo.local=/some_path/.m2_new_2 clean install

Speak Your Mind