我将我们的应用程序从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 wars或executable and deployable wars。
关于spring-boot - Spring Boot 2.x Repackage用于与Gradle的集成测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59649688/