gpt4 book ai didi

spring-boot - 如何使用Gradle Kotlin DSL对Spring Boot应用程序进行Docker化

转载 作者:行者123 更新时间:2023-12-02 12:57:57 25 4
gpt4 key购买 nike

我正在遵循Dockerize a Spring Boot application指南。关键是我正在使用Gradle的Kotlin DSL,但无法将原始Groovy语法转换为Kotlin。

这是指南中的原始Groovy:

task unpack(type: Copy) {
dependsOn bootJar
from(zipTree(tasks.bootJar.outputs.files.singleFile))
into("build/dependency")
}

docker {
name "${project.group}/${bootJar.baseName}"
copySpec.from(tasks.unpack.outputs).into("dependency")
buildArgs(['DEPENDENCY': "dependency"])
}

这是我到目前为止获得的Kotlin:
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id("org.springframework.boot") version "2.2.0.M4"
id("io.spring.dependency-management") version "1.0.7.RELEASE"
id("com.palantir.docker") version "0.22.1"
kotlin("jvm") version "1.3.31"
kotlin("plugin.spring") version "1.3.31"
}

group = "com.something"
version = "1.0.0-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_1_8

repositories {
mavenCentral()
}

dependencies {
implementation("org.springframework.boot:spring-boot-starter-webflux")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
// ...
}

最佳答案

Yoni Gibbs的答案提供了一个好的开始,但这对我有用:

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.springframework.boot.gradle.tasks.bundling.BootJar

plugins {
id("org.springframework.boot") version "2.1.6.RELEASE"
id("io.spring.dependency-management") version "1.0.7.RELEASE"
kotlin("jvm") version "1.2.71"
kotlin("plugin.spring") version "1.2.71"
id("com.palantir.docker") version "0.22.1"
}

task<Copy>("unpack") {
val bootJar = tasks.getByName<BootJar>("bootJar")
dependsOn(bootJar)
from(zipTree(bootJar.outputs.files.singleFile))
into("build/dependency")
}

docker {
val archiveBaseName = tasks.getByName<BootJar>("bootJar").archiveBaseName.get()
name = "${project.group}/$archiveBaseName"
copySpec.from(tasks.getByName<Copy>("unpack").outputs).into("dependency")
buildArgs(mapOf("DEPENDENCY" to "dependency"))
}

关于spring-boot - 如何使用Gradle Kotlin DSL对Spring Boot应用程序进行Docker化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57091575/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com