0

我正在开发一个 Spring Boot 应用程序,作为我的 maven 项目的集成测试阶段的一部分,我已将 spring-boot maven 插件配置为在构建的前后集成测试部分期间启动和关闭,如下所示:

        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                <execution>
                    <id>pre-integration-test</id>
                    <goals>
                        <goal>start</goal>
                    </goals>
                </execution>
                <execution>
                    <id>post-integration-test</id>
                    <goals>
                        <goal>stop</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

但是,我这样做只是为了让我的开发人员可以针对服务的本地实例运行他们的测试。在 Jenkins 上,我将针对已部署该服务的外部服务运行测试,并且我不需要在 Jenkins 作业中启动 Spring Boot 应用程序。

有没有办法让我通过 mvn 命令行覆盖显式阻止 spring-boot maven 插件启动服务?

4

1 回答 1

1

当然,您可以为其公开一个属性,例如

  <properties>
    <skip.it>false</skip.it>
  </properties>

    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <executions>
            <execution>
                <id>pre-integration-test</id>
                <goals>
                    <goal>start</goal>
                </goals>
                <configuration>
                  <skip>${skip.it}</skip>
                </configuration>
            </execution>
            <execution>
                <id>post-integration-test</id>
                <goals>
                    <goal>stop</goal>
                </goals>
                <configuration>
                  <skip>${skip.it}</skip>
                </configuration>
            </execution>
        </executions>
    </plugin>

完成后,按如下方式运行命令:mvn verify -Dskip.it=trueSpring Boot 应用程序将不会作为集成测试的一部分启动。

于 2016-11-23T08:43:13.833 回答