How to get the Maven local repo location?

Maven 2Maven

Maven 2 Problem Overview


Is there a way to get the Maven local repo location?

Using the following command you can force Maven to use a specific setting file:

 mvn -s < path to settings file >

I know you can edit settings.xml file to set a repository location, but can I get the current default value with some Maven command?

Maven 2 Solutions


Solution 1 - Maven 2

If you want just the local repo, try this:

mvn help:evaluate -Dexpression=settings.localRepository | grep -v '\[INFO\]'

EDIT

I'm revisiting this after years because recent versions of the Maven help plugin introduced a useful parameter for the evaluate goal called forceStdout that allows us to remove the need to grep the output:

mvn help:evaluate -Dexpression=settings.localRepository -q -DforceStdout

Solution 2 - Maven 2

Yes, you can get it with the -X or --debug option, e.g. mvn -X

...
[DEBUG] Reading global settings from C:\Maven\conf\settings.xml
[DEBUG] Reading user settings from C:\segphault\.m2\settings.xml
[DEBUG] Using local repository at C:\Repo
...

Solution 3 - Maven 2

The Maven Help plugin will show local settings, including the local repository path.

You want the command:

mvn help:effective-settings

Output will show settings in XML format. Look for the localRepository element:

<localRepository xmlns="http://maven.apache.org/SETTINGS/1.1.0">/home/jrs/.mavenRepo</localRepository>

Solution 4 - Maven 2

In the meantime you can do that in a simpler way:

mvn help:evaluate -Dexpression=settings.localRepository -q -DforceStdout

You can also directly use that to assign that a shell variable like this:

RESULT=$(mvn help:evaluate -Dexpression=settings.localRepository -q -DforceStdout)

Important note: Use most recent version of Maven and of course most recent vesion of maven-help-plugin...

This will contain the result without a new line etc.

Solution 5 - Maven 2

It should be in the /home/.m2 directory, the folder is probably hidden. So, you'll need to Ctrl+H to see hidden folders.

Solution 6 - Maven 2

For windows users

Usually it's in: C:\Users\USER_NAME\.m2\repository.
However the mvn help:effective-settings command will surely show the local path in response xml.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questioncode-gijoeView Question on Stackoverflow
Solution 1 - Maven 2adutraView Answer on Stackoverflow
Solution 2 - Maven 2Justin GarrickView Answer on Stackoverflow
Solution 3 - Maven 2JRSView Answer on Stackoverflow
Solution 4 - Maven 2khmarbaiseView Answer on Stackoverflow
Solution 5 - Maven 2Aboozar RajabiView Answer on Stackoverflow
Solution 6 - Maven 2Shubham PandeyView Answer on Stackoverflow