java - 如何使用不同的系统属性值执行两个完全相同的 Maven 配置文件?
问题描述
我的pom
文件中有以下提到的实现
<profile>
<id>test</id>
<activation>
<activeByDefault>true</activeByDefault>
<property>
<name>test</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xml-maven-plugin</artifactId>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>transform</goal>
</goals>
</execution>
</executions>
<configuration>
<transformationSets>
<transformationSet>
<includes>
<include>set.xml</include>
</includes>
<dir>test/resources/</dir>
<stylesheet>
test/resources/ser.xsl
</stylesheet>
<outputDir>test/resources</outputDir>
</transformationSet>
</transformationSets>
</configuration>
<dependencies>
<dependency>
<groupId>net.sf.saxon</groupId>
<artifactId>saxon</artifactId>
<version>8.7</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<inherited>false</inherited>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
<systemProperties>
<property>
<name>maven.test.haltafterfailure</name>
<value>false</value>
</property>
<property>
<name>java.io.tmpdir</name>
<value>${basedir}/target/</value>
</property>
<property>
<name>isValid</name>
<value>false</value>
</property>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
</profile>
我希望这个配置文件再次执行,系统属性isValid
是true
当我复制这个配置文件配置并再次添加它时,isValid
等于true
第一个配置文件配置被覆盖。
从 Maven 文档...
除非使用上述方法之一激活同一 POM 中的另一个配置文件,否则此配置文件将自动对所有构建处于活动状态。当 pom 中的配置文件在命令行上或通过其激活配置激活时,默认情况下处于活动状态的所有配置文件都会自动停用。...
我尝试添加两个执行,如下所示:
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>transform</goal>
</goals>
<configuration>.... </configuration>
</execution>
<execution>
<phase>compile</phase>
<goals>
<goal>transform</goal>
</goals>
<configuration>.... </configuration>
</execution>
</executions>
但我不知道如何使用xml-maven-plugin<suiteXmlFile>
设置系统变量和属性<execution>
我需要使用什么插件来实现我的要求?
有没有办法使用系统属性 isValid 运行这 2 个配置文件,true
同时false
使用不同的<suiteXmlFile>
值(不同的 testng 文件)?
解决方案
如果您复制配置文件,那么您定义了两次相同的插件,因此配置被覆盖。
相反,定义两个<executions>
相同的插件。
推荐阅读
- .net - 需要在 PC 上安装哪个版本的 .net(WPF、Prism7)?
- javascript - 为什么我们需要 this.events[type] || [] 行是否可以正常工作?
- python - 使用 Python 执行时,终端命令不起作用
- go - golang 资源所有权模式(文件、连接、可关闭)
- augmented-reality - 将 glTF 模型加载到 RealityKit 场景中?
- javascript - 如何使用按钮隐藏和显示文本?
- python-3.x - 使用 CNN 模型学习 n-gram 特征 使用 keras 使用 python 逐步学习文本数据
- ios - 如何在 macOS 上打开蒸汽项目
- python - django core.mail.send_mail 工作正常,但 EmailMessage.send 失败
- python-3.x - 使用 try | 创建一个 continue 循环 Python3