spring-boot - Spring Boot 2.x Repackage用于与Gradle的集成测试

标签 spring-boot gradle integration-testing

我将我们的应用程序从Spring Boot 1.5迁移到了Spring Boot 2.2。我正在努力建立我们的gradle。过去,我们使用以下命令获取具有所有Spring依赖项的可执行Jar文件,以分别在CI管道中运行集成测试:

task integrationBootRepackage(type: BootRepackage, dependsOn: integrationJar) {
  enabled = true
  withJarTask = integrationJar
  customConfiguration = "integrationRuntime"
  mainClass = "io.test.IntegrationApplicationKt"
}
assemble.dependsOn integrationBootRepackage

integrationJar任务使用我们的集成测试类和主类构建一个基本jar。过去,我们可以通过重新打包任务“启动”此jar。但是在Spring Boot 2.2中,此任务不再存在。 Spring Documentation仅告诉您如何构建主要的JAR。

使用Maven重新打包似乎仍然可用,因为Spring Maven plugin documentation中提到了以下部分:

You can also use the same configuration if you want to repackage a secondary artifact the same way the main artifact is replaced. The following configuration installs/deploys a single task classified artifact with the repackaged app:



有谁知道为什么Maven仍然可以使用重新包装,而gradle却不可用?还是我只是找不到合适的文档?

我还尝试了其他方法,例如直接从BootJar继承我们的integrationJar任务,但是它没有将spring依赖项放入jar中。
val integrationJar = tasks.register("integrationJar", BootJar::class) {
  description = "Assembles a jar archive containing the integration classes."
  group = "build"
  mainClassName = "io.test.IntegrationApplicationKt"
  archiveAppendix.set("integration")

  from(sourceSets!!["main"].output)
  from(sourceSets["integration"].output)
}

任何人都可以在我如何使用Spring Boot 2.2实现Spring repackaged IntegrationJar文件以及与Kotlin DSL结合使用方面提供一些帮助吗?

最佳答案

您必须查看Spring Boot Gradle Plugin的文档。特别是在4.1. Packaging executable jars部分。

Executable jars can be built using the bootJar task. The task is automatically created when the java plugin is applied and is an instance of BootJar. The assemble task is automatically configured to depend upon the bootJar task so running assemble (or build) will also run the bootJar task.



您还可以执行executable warsexecutable and deployable wars

关于spring-boot - Spring Boot 2.x Repackage用于与Gradle的集成测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59649688/

相关文章:

c# - 如何在集成测试之间刷新 IAppCache

javascript - 测试expressJS的基本中间件

tomcat - 在部署到 Tomcat 上进行集成测试之前修改 my.war/WEB-INF/中的配置文件

spring - 找不到正在获取项目 'org.springframework.boot:spring-boot-starter-parent:2.6.0-SNAPSHOT'

java - 为 Spring Boot 微服务设置集成测试

gradle - 如何在自定义插件中创建源集

gradle - 在build.gradle中更改胶水

mysql - Spring Boot JPA 一对一映射生成 StackOverflow 错误

java - Spring boot 不提供 src/main/resources/public 目录中的某些图像

maven - maven杀死了 Ant 还是它还活着?