【问题标题】:Prevent springboot failsafe plugin default execution防止springboot故障保护插件默认执行
【发布时间】:2019-05-28 12:55:08
【问题描述】:

我有一个示例 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.xml 中找不到它,它会在集成测试阶段运行其默认的故障保护插件。

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

我可以在我的 pom 中添加它以使其工作 -

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

但这看起来并不直观。

还有其他办法吗?

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

【问题讨论】:

  • 为什么要为 maven-failsafe-plugin 添加另一个配置 ..Spring Boot 已经定义了一个 ...?你为什么想要另一个?
  • 我有一些复杂的测试要求,默认执行无法满足。
  • 这是什么意思?如果你真的有比我的经验更复杂的测试要做,那就是你做错了......只是一个猜测......
  • 我需要使用不同的配置多次运行我的所有 IT。因此,我的个人资料中将包含多个执行步骤。所有执行步骤都会有一个 id 并且不会有默认执行。所以 spring 将使用我不想要的故障安全运行它的默认执行步骤。

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


【解决方案1】:

请检查以下内容。此处,默认执行已被禁用:

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

【讨论】:

    【解决方案2】:

    以下可能是删除 groupId 和 execution 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] ------------------------------------------------------------------------
    
    

    【讨论】:

    • 但是我需要 id 因为会有多个执行步骤。
    猜你喜欢
    • 1970-01-01
    • 2021-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-19
    • 2011-06-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多