是否可以更改用户安装设置的默认路径.xml(${user.home}/.m2/settings.xml)?



在项目之外,没有pom.xml时,是否总是可以更改Maven期望用户设置的位置?比如,从用户主目录下的终端窗口?

我已经阅读了好几天,但我在apache网站,谷歌或这里找不到答案。在https://maven.apache.org/settings.html中它说:

settings.xml文件可能存在两个位置:

The Maven install: ${maven.home}/conf/settings.xml
A user’s install: ${user.home}/.m2/settings.xml

我想在我的机器上更改Maven安装/程序的实际配置,以查找用户在其他地方的设置,总是:/home/userFoo/bin/maven.config.directory/settings.xml而不是/home/userFoo/.m2/settings.xml

settings.xml文件说:

<!--
 | This is the configuration file for Maven. It can be specified at two levels:
 |
 |  1. User Level. This settings.xml file provides configuration for a single user,
 |                 and is normally provided in ${user.home}/.m2/settings.xml.
 |
 |                 NOTE: This location can be overridden with the CLI option:
 |
 |                 -s /path/to/user/settings.xml

但是当我运行这个命令时,mvn -s /home/userFoo/bin/maven.config.directory/settings.xml我得到了许多错误

您可以设置MAVEN_OPTS环境变量以覆盖JVM中的user.home

export MAVEN_OPTS=-Duser.home=/home/userFoo/bin/maven.config.directory
# do something with Maven
mvn dependency:list

或Windows

set MAVEN_OPTS=-Duser.home=D:homeuserFoobinmaven.config.directory
:: do something with Maven
mvn dependency:list

您还可以将MAVEN_OPTS添加到您的。bashrc, .profile或Windows环境中。

您可以尝试使用以下命令:

mvn --settings /home/userFoo/bin/maven.config.directory/settings.xml archetype:generate

您可以通过检查命令的输出来验证您的自定义设置文件是否正在加载:

mvn --settings /home/userFoo/bin/maven.config.directory/settings.xml help:effective-settings

如果您希望从共享位置加载,甚至可以更改默认的全局设置文件位置,方法是在目标之前附加上述命令:

--global-settings /${shared.location}/settings.xml

您可能还想为命令创建一个别名,以防您不想每次都输入它。

把这个放在这里,因为这是我唯一能让它工作的方法,但感觉不对:

在${user.home}/.m2/settings.xml下创建软链接:

ln -s ~/.m2/settings.xml ~/bin/maven.config.directory/settings.xml

最新更新