Sarangan
Sarangan

Reputation: 1017

How to execute two exactly same maven profiles with a different system property value?

I have the below-mentioned implementation in my pom file

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

I want this profile to execute again with the system property isValid is true When I replicate this profile config and added it again with isValid equals true the first profile config is getting overridden.

From Maven documentation...

This profile will automatically be active for all builds unless another profile in the same POM is activated using one of the previously described methods. All profiles that are active by default are automatically deactivated when a profile in the pom is activated on the command line or through its activation config. ...

I tried to add two executions as below:

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

But I don't know how to set the system variables and <suiteXmlFile> property inside <execution> with xml-maven-plugin

What plugin do I need to use to achieve my requirement?

Is there a way to run these 2 profiles with the system property isValid equals to true and false and with different <suiteXmlFile> values(different testng files) at once?

Upvotes: 1

Views: 676

Answers (1)

J Fabian Meier
J Fabian Meier

Reputation: 35901

If you replicate the profile, then you define the same plugin twice and so the configuration is overridden.

Instead, define two <executions> of the same plugin.

Upvotes: 2

Related Questions