如何配置kotlin dsl使springboot多个模块打包成可执行jar文件

如何配置kotlin dsl使springboot多个模块打包成可执行jar文件。

刚开始用kotlin dsl,查了很多资料都没有成功。

我尝试了很多方法来构建不包含我自己代码的文件。

这是一些代码

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    id("application")
    id("org.springframework.boot") version "2.5.2"
    id("io.spring.dependency-management") version "1.0.11.RELEASE"
    kotlin("jvm") version "1.5.20"
    kotlin("kapt") version "1.5.20"
    kotlin("plugin.spring") version "1.5.20"
    id("com.github.johnrengelman.shadow") version "5.1.0"
}

group = "com.example"
version = "1.0-snAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_1_8

tasks.withType<KotlinCompile> {
    kotlinOptions {
        freeCompilerArgs = listOf("-Xjsr305=strict")
        jvmTarget = "1.8"
    }
}

tasks.getByName<KotlinCompile>("compileKotlin") {
    kotlinOptions {
        freeCompilerArgs = listOf("-Xjsr305=strict")
        jvmTarget = "1.8"
    }
}

tasks.withType<Test> {
    useJUnitPlatform()
}
val fatJar = task("fatJar",type = Jar::class) {
    manifest {
        attributes["Main-Class"] = "com.example.MainApplicationKt"
    }
    from(configurations.runtimeclasspath.get().map({ if (it.isDirectory) it else zipTree(it) }))
    // with(jar.get() as CopySpec)
    with(tasks.jar.get() as CopySpec)
}

tasks {
    "build" {
        dependsOn(fatJar)
    }
}
asdf564e 回答:如何配置kotlin dsl使springboot多个模块打包成可执行jar文件

谢谢,但我还有一个问题。未解决的参考:实现

subprojects {
apply(plugin = "java")
apply(plugin = "idea")
apply(plugin = "kotlin-kapt")
apply(plugin = "java-library")
apply(plugin = "org.jetbrains.kotlin.jvm")
apply(plugin = "io.spring.dependency-management")
apply(plugin = "org.springframework.boot")

java.sourceCompatibility = JavaVersion.VERSION_1_8
java.targetCompatibility = JavaVersion.VERSION_1_8

extra.apply {
    set("mybatisPlusVersion","3.4.3.1")
}

dependencies {
    implementation(kotlin("stdlib"))
    // implementation(kotlin("stdlib-jdk8"))
}
dependencyManagement {
    imports {
        mavenBom("org.springframework.boot:spring-boot-dependencies:2.3.12.RELEASE")
    }
}

project(":timemail-dto") {
    tasks {
        named<BootJar>("bootJar") {
            enabled = false
        }
        named<Jar>("jar") {
            enabled = true
        }
    }
}

project(":timemail-server").tasks{
    named<BootJar>("bootJar") {
        enabled = false
    }
    named<Jar>("jar") {
        enabled = true
    }
}

}

本文链接:https://www.f2er.com/1441.html

大家都在问