【发布时间】:2021-11-16 19:13:01
【问题描述】:
一般来说,在处理maven 项目时,settings.xml 的默认版本中有properties,我将其称为$MAVEN_HOME/conf/settings.xml。一个例子可能是
<settings>
[...]
<profiles>
<profile>
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<sonar.host.url>https://server1/</sonar.host.url>
这里属性的键值是:
key: sonar.host.url
property: https://server1/
您还可以拥有 maven settings.xml 的项目本地版本。在这个文件中是内容:
<properties>
<sonar.host.url>https://server2/</sonar.host.url>
这里属性的键值是:
key: sonar.host.url
property: https://server2/
如果您不向 maven 构建传递任何参数 - 那么它默认采用 $MAVEN_HOME/conf/settings.xml 设置。例如
mvn compile
这将使用
<sonar.host.url>https://server1/</sonar.host.url>
我曾预计,如果您传递一个项目本地设置文件,即-s settings.xml,那么它将总是覆盖$MAVEN_HOME/conf/settings.xml 中的默认 maven 设置,即运行
mvn -s settings.xml compile
会用什么方法
<sonar.host.url>https://server2/</sonar.host.url>
今天我看到了相反的情况,并试图找出原因。今天看到跑步了
mvn -s settings.xml compile
始终使用该值
<sonar.host.url>https://server1/</sonar.host.url>
即默认$MAVEN_HOME/conf/settings.xml 文件中的值覆盖项目本地settings.xml 文件。
为了测试这个 - 然后我去删除了这个值
<sonar.host.url>https://server1/</sonar.host.url>
从默认版本的$MAVEN_HOME/conf/settings.xml - 然后它改变了。在我从默认 settings.xml 中删除该行后,它开始使用
<sonar.host.url>https://server2/</sonar.host.url>
我的问题是:maven 如何允许 $MAVEN_HOME/conf/settings.xml 覆盖项目本地参数 -s settings.xml ?
【问题讨论】: