阻止springboot故障安全插件默认执行

时间:2019-05-28 12:55:09

标签: java maven spring-boot maven-surefire-plugin

我有一个示例springboot java应用程序。 这是我的pom文件

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

当我运行mvn verify -Pprofile1时,故障安全插件将运行两次。

以下是日志-

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

当我删除springboot starter父pom时,故障安全插件将按预期运行一次。这是该日志-

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

因此,如果springboot在我的pom中找不到一个默认的故障安全插件,则它将在集成测试阶段运行。

我无法在故障保护插件声明中添加默认执行步骤。 如何停止springboot以停止运行其故障保护插件?

我可以在pom中添加它以使其起作用-

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

但这看起来并不直观。

还有其他办法吗?

我不想在pom文件中添加springboot插件

2 个答案:

答案 0 :(得分:0)

以下可能是删除groupId和执行ID标记的解决方案:


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

使用上述更改执行mvn verify -Pprofile1时,结果如下:


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

答案 1 :(得分:0)

请检查以下内容。在这里,默认执行已被禁用:

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