在 Gradle 构建中,启动 Spring boot 应用程序,运行测试,然后停止 Spring boot 应用程序

sva*_*ret 6 spring integration-testing gradle spring-boot

通过 Gradle 构建,我想启动 Spring Boot 应用程序,运行一些测试,然后关闭 Spring Boot 应用程序。首先,我尝试启动服务器然后关闭,暂时不进行测试。

我的 build.gradle 文件的一部分如下所示

bootRun {
    systemProperties = System.properties
}

task shutdown(type: org._10ne.gradle.rest.RestTask) {
    httpMethod = 'post'
    uri = 'http://localhost:8080/shutdown'
}

task integrationTest() {
    dependsOn bootRun
    finalizedBy shutdown
}
Run Code Online (Sandbox Code Playgroud)

我像这样从命令行开始构建

gradle integrationTest -Dendpoints.shutdown.enabled=true
Run Code Online (Sandbox Code Playgroud)

构建会启动 Spring Boot 应用程序,但它不会(当然)继续执行关闭任务。我可以单独运行关闭任务,它将关闭 Spring Boot 应用程序。

但是,如何让服务器在同一个构建中运行和关闭?

Eri*_*ich 1

我不确定它是否适用于像这样的任务bootRun,但我认为您正在寻找类似ParallelizedTask 的东西

此外,您还必须传递--parallel命令行选项。