[英]How to get the Maven local repo location?
Is there a way to get the Maven local repo location?有没有办法获得 Maven 本地回购位置?
Using the following command you can force Maven to use a specific setting file:使用以下命令可以强制 Maven 使用特定的设置文件:
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?我知道您可以编辑
settings.xml
文件来设置存储库位置,但是我可以使用某些 Maven 命令获取当前默认值吗?
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:多年后我重新审视这个问题,因为最近版本的 Maven 帮助插件为
evaluate
目标引入了一个有用的参数,称为forceStdout
,它允许我们消除 grep 输出的需要:
mvn help:evaluate -Dexpression=settings.localRepository -q -DforceStdout
Yes, you can get it with the -X
or --debug
option, eg mvn -X
是的,您可以使用
-X
或--debug
选项获取它,例如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
...
The Maven Help plugin will show local settings, including the local repository path. Maven 帮助插件将显示本地设置,包括本地存储库路径。
You want the command:你想要命令:
mvn help:effective-settings
Output will show settings in XML format.输出将以 XML 格式显示设置。 Look for the localRepository element:
查找 localRepository 元素:
<localRepository xmlns="http://maven.apache.org/SETTINGS/1.1.0">/home/jrs/.mavenRepo</localRepository>
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:您也可以直接使用它来分配一个 shell 变量,如下所示:
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...重要说明:使用最新版本的 Maven,当然还有最新版本的 maven-help-plugin...
This will contain the result without a new line etc.这将包含没有新行等的结果。
It should be in the /home/.m2 directory, the folder is probably hidden.它应该在 /home/.m2 目录中,该文件夹可能是隐藏的。 So, you'll need to Ctrl+H to see hidden folders.
因此,您需要按 Ctrl+H 才能查看隐藏文件夹。
Usually it's in: C:\\Users\\USER_NAME\\.m2\\repository
.通常它在:
C:\\Users\\USER_NAME\\.m2\\repository
。
However the mvn help:effective-settings
command will surely show the local path in response xml.但是
mvn help:effective-settings
命令肯定会在响应 xml 中显示本地路径。
Is there a way to get the Maven local repo location?有没有办法获取Maven本地仓库的位置?
Using the following command you can force Maven to use a specific setting file:使用以下命令,您可以强制Maven使用特定的设置文件:
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?我知道您可以编辑
settings.xml
文件来设置存储库位置,但是我可以通过一些Maven命令获得当前的默认值吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.