0

I have a sample springboot java application. This is my pom file

    <groupId>com.sample.this</groupId>
    <artifactId>example</artifactId>
    <version>1.0-SNAPSHOT</version>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.2.RELEASE</version>
    </parent>

<profiles>
    <profile>
        <id>profile1</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-failsafe-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>id1</id>
                            <goals>
                                <goal>integration-test</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

When I run mvn verify -Pprofile1, the failsafe plugin runs twice.

Here are the logs -

[INFO] --- maven-failsafe-plugin:2.22.1:integration-test (default) @ junit.example ---
.
.
.
[INFO] --- maven-failsafe-plugin:2.22.1:integration-test (id1) @ junit.example ---

When I remove springboot starter parent pom, then the failsafe plugin runs once as expected. Here is that log -

[INFO] --- maven-failsafe-plugin:2.22.1:integration-test (id1) @ junit.example ---

So, springboot runs its default failsafe plugin in integration-test phase if it doesnt find one in my pom.

I cant add a default execution step in my failsafe plugin declaration. How do I stop springboot to stop running its failsafe plugin ?

I can add this in my pom to make it work -

                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                        </goals>
                        <configuration>
                            <skipITs>true</skipITs>
                        </configuration>
                    </execution>

But this doesnt look intuitive .

Is there any other way around ?

I dont want to add springboot plugin in my pom file

  • Why have you added another configuration for maven-failsafe-plugin ..Spring Boot has already one defined ...? Why would you like to have another? – khmarbaise May 28 '19 at 12:59
  • I have some complex testing requirements which cannot be met with a default execution. – lostintranslation May 28 '19 at 14:57
  • What does that mean? If you really have complex testings to do than my experience is that you are doing it wrong....only a guess... – khmarbaise May 28 '19 at 15:25
  • I need to run all my IT multiple times with different configurations. So my profile will have multiple execution steps in it. All the execution steps will have an id and there wont be a default execution . So spring will run its default execution step with failsafe which I dont want. – lostintranslation May 28 '19 at 15:44
  • Possible duplicate of [Is it possible to override executions in maven pluginManagement?](https://stackoverflow.com/questions/17440418/is-it-possible-to-override-executions-in-maven-pluginmanagement) – crizzis May 28 '19 at 18:22
  • Following link should provide you the solution: https://docs.spring.io/spring-boot/docs/2.1.5.RELEASE/maven-plugin/examples/it-skip.html – Anshul Singhal May 29 '19 at 08:15
  • Only if i add the spring plugin right ? – lostintranslation May 29 '19 at 09:20

2 Answers2

1

Please check the following. Here, default execution has been disabled:

     <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.2.RELEASE</version>
    </parent>

    <profiles>
        <profile>
            <id>profile1</id>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>default</id>
                                <phase>none</phase>
                            </execution>
                            <execution>
                                <id>id1</id>
                                <goals>
                                    <goal>integration-test</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

Anshul Singhal
  • 1,983
  • 20
  • 25
0

Following could be the solution where groupId and execution id tags are removed:


    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.2.RELEASE</version>
    </parent>

    <profiles>
        <profile>
            <id>profile1</id>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>integration-test</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

When mvn verify -Pprofile1 is executed with above changes then following is the result:


[INFO] ------------------------------------------------------------------------
[INFO] Building test 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-failsafe-plugin:2.22.1:integration-test (default) @ test ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-failsafe-plugin:2.22.1:verify (default) @ test ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

Anshul Singhal
  • 1,983
  • 20
  • 25