【问题标题】:How does maven allow the $MAVEN_HOME/conf/settings.xml to override the project local param -s settings.xml?maven 如何允许 $MAVEN_HOME/conf/settings.xml 覆盖项目本地参数 -s settings.xml?
【发布时间】: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>

我的问题是:ma​​ven 如何允许 $MAVEN_HOME/conf/settings.xml 覆盖项目本地参数 -s settings.xml

【问题讨论】:

    标签: maven settings


    【解决方案1】:

    通常,您不会在$MAVEN_HOME/conf/settings.xml 中添加或更改任何内容。

    相反,您使用用户目录中的settings.xml 文件,然后使用.m2/settings.xml

    我想如果你这样做,你的“奇怪”行为就会消失。

    【讨论】:

      猜你喜欢
      • 2013-11-23
      • 1970-01-01
      • 1970-01-01
      • 2016-07-25
      • 1970-01-01
      • 2022-01-17
      • 2020-06-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多