首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >无法从配置文件配置文件追加系统属性

无法从配置文件配置文件追加系统属性
EN

Stack Overflow用户
提问于 2018-08-18 12:27:10
回答 1查看 309关注 0票数 6

我有maven failsafe插件的构建配置,其中包括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>

但我无法读取此配置文件中的属性。如果我在build plugin configuration部分删除systemPropertyVariables,并保留profile的pluginManagement配置,则可以正常工作。在一起使用时,我似乎需要合并这些属性,所以我尝试将combine.children="append"combine.self="append"添加到插件的configuration中,但无济于事。

更新:我已经找到了这个问题的原因:我没有提到我有parent pom,包括这个,parent 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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-06-26 16:10:26

我设法做到了这一点,在不可触及(或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

附注:不要忘记为test配置文件添加某种类型的<activation>

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51905256

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档