gpt4 book ai didi

maven - 无法从配置文件配置附加系统属性

转载 作者:行者123 更新时间:2023-12-04 15:50:28 25 4
gpt4 key购买 nike

我有 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 引用并且不能修改它(实际上我可以对它进行 fork 和编辑,但这不是一件容易的事),是否可以覆盖这些属性,因为我不使用它们?

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

最佳答案

我设法通过在 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 作为它的父级。
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

附言不要忘记添加某种 <activation>test轮廓

关于maven - 无法从配置文件配置附加系统属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51905256/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com