【问题标题】:Can not append system properties from profile config无法从配置文件配置附加系统属性
【发布时间】:2019-01-25 01:53:33
【问题描述】:

我有 maven 故障安全插件的构建配置,其中包括 systemPropertyVariables:

<build>
  <plugins>
    <plugin>
        <artifactId>maven-failsafe-plugin</artifactId>
        <version>2.19.1</version>
        <executions>
          <execution>
            <goals>
              <goal>integration-test</goal>
              <goal>verify</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <systemPropertyVariables>
            <buildDirectory>${project.build.directory}</buildDirectory>
          </systemPropertyVariables>
        </configuration>
      </plugin>
  </plugins>
</build>

我还有一个配置文件,可以通过pluginManagement 将一些属性附加到同一个插件:

<profile>
  <id>test</id>
  <activation>
    <property>
      <name>test.host</name>
    </property>
  </activation>
  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-failsafe-plugin</artifactId>
          <configuration>
            <systemPropertyVariables>
              <TEST_HOST>test.host</TEST_HOST>
            </systemPropertyVariables>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</profile>

但我无法从此配置文件中读取属性。如果我在构建插件配置部分中删除 systemPropertyVariables 并保留在配置文件的 pluginManagement 配置中,它工作正常。看来我需要在一起使用时合并这些属性,所以我尝试将combine.children="append"combine.self="append"添加到插件的configuration,但没有帮助。

更新: 我找到了这个问题的原因:我没有提到我有父 pom,包括来自这个的,而父 pom.xml 有这些行:

      <plugin>
        <artifactId>maven-failsafe-plugin</artifactId>
        <groupId>org.apache.maven.plugins</groupId>
        <version>3.0.0-M3</version>
        <configuration combine.children="append"> 
          <systemProperties>
            <!-- some properties that I don't use -->
          </systemProperties>
        </configuration>
      </plugin>

这些父 pom 故障安全配置正在破坏我的 pom.xml 中的所有配置 - 如果我删除父 pom 引用,故障安全属性将被正确包含。我不能只删除父 pom 引用并且不能修改它(实际上我可以分叉和编辑它,但这不是一件容易的事),是否可以覆盖这些属性,因为我不使用它们?

附加最小可重现项目:https://send.firefox.com/download/88dfb9f933c9567f/#71ij1jbuEuAYgdwIiZQZRg

【问题讨论】:

  • 你能提供一个可下载的例子吗?
  • 你试过mvn help:effective-pom -Ptest这样的做法吗?在这里快速尝试,使用上面的 XML,在 &lt;systemPropertyVariables&gt; 下显示 &lt;buildDirectory&gt;&lt;TEST_HOST&gt;
  • @MarinosAn @df778899 很抱歉回复太长,没有时间更深入地检查,我更新了有关pom.xml的更多详细信息

标签: maven pom.xml maven-profiles


【解决方案1】:

我设法通过在 untouchable(或 pariah)父级和当前 child 之间添加一个额外的 pom 来做到这一点,我称这个新的中间 pom midboy =)

所以midboypariah只有以下区别;

<plugin>
    <artifactId>maven-failsafe-plugin</artifactId>
    <groupId>org.apache.maven.plugins</groupId>
    <version>3.0.0-M3</version>
    <inherited>false</inherited>
</plugin>

并且这个 pom 成为 child 的新父 pom,而它使用原来的 pariah pom 作为其父 pom。

child ---[继承]---> midboy ---[继承]---> pariah

使用inherited:false,我基本上切断了传递到child 的故障安全插件,并打破了其基于配置文件的配置添加到它自己的本地故障安全插件和配置中。并且效果很好!

这次不要跳过测试! ?

Running com.test.so51905256.PropITCase
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.031 s - in com.test.so51905256.PropITCase

附言不要忘记为test 个人资料添加某种&lt;activation&gt;

【讨论】:

    猜你喜欢
    • 2011-03-21
    • 1970-01-01
    • 2023-03-17
    • 1970-01-01
    • 2019-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-11
    相关资源
    最近更新 更多