How to get the Maven local repo location?

时光怂恿深爱的人放手 提交于 2019-12-17 15:13:51

问题


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?


回答1:


If you want just the local repo, try this:

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



回答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
...



回答3:


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>



回答4:


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.




回答5:


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




回答6:


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




回答7:


You can achieve this by enabling debug mode by using the -X option and find out the line mentioning the local repository being used.



来源:https://stackoverflow.com/questions/5916157/how-to-get-the-maven-local-repo-location

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!