【问题标题】:How to execute two exactly same maven profiles with a different system property value?如何使用不同的系统属性值执行两个完全相同的 Maven 配置文件?
【发布时间】:2021-03-24 11:52:32
【问题描述】:

我的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>

我希望此配置文件再次执行,系统属性 isValidtrue 当我复制此配置文件配置并使用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

&lt;execution&gt; 中设置系统变量和&lt;suiteXmlFile&gt; 属性

我需要使用什么插件来实现我的要求?

有没有办法使用系统属性 isValid 等于 truefalse 并使用不同的 &lt;suiteXmlFile&gt; 值(不同的 testng 文件)同时运行这两个配置文件?

【问题讨论】:

    标签: java maven build maven-2 maven-3


    【解决方案1】:

    如果您复制配置文件,那么您定义了两次相同的插件,因此配置被覆盖。

    相反,定义同一个插件的两个&lt;executions&gt;

    【讨论】:

    • 我们如何在 &lt;executions&gt; 中指定 &lt;system variables&gt;&lt;suiteXmlFile&gt; 。我认为他们不允许进入&lt;executions&gt;
    • 你试过了吗?我会将其放入&lt;execution&gt; 内的&lt;configuration&gt; 块中。
    • 我们可以将&lt;configuration&gt;指定为&lt;execution&gt;。但是,当我使用`xml-maven-plugin`时,它不允许我输入&lt;systemVariables&gt;
    • 是的,但在您的解决方案中,情况也是如此。此外,您需要 xml maven 插件中的系统变量做什么?
    • 我需要运行两次测试。在第一次运行时,它应该运行isValid=true,然后运行isValid=false。如果我们不能在 xml maven 插件中指定它,我们该怎么做?
    猜你喜欢
    • 2019-07-20
    • 1970-01-01
    • 2016-03-15
    • 1970-01-01
    • 2017-10-11
    • 2014-05-23
    • 1970-01-01
    • 2020-06-10
    • 2016-02-07
    相关资源
    最近更新 更多