kotlin multiplatform shadow fat jar 和 runShadow 任务?

kotlin multiplatform shadow fat jar and runShadow task?

我有一个相当标准的 kotlin 多平台 (mpp) build.gradle.kts,它使用应用程序插件和 com.github.johnrengelman.shadow

我成功创建了一个 java -jar 可执行 fat jar:

新解决方案:

编辑: 我将一行扩展到@Pylyp Dukhov 解决方案:

    classpath += files("$buildDir/processedResources/jvm/main")
tasks {
    named<JavaExec>("run") {
        standardInput = System.`in`
        classpath += objects.fileCollection().from(
            named("compileKotlinJvm"),
            configurations.named("jvmRuntimeClasspath")
        )
        classpath += files("$buildDir/processedResources/jvm/main")
    }
    shadowJar {
        manifest { attributes["Main-Class"] = theMainClass }
        archiveClassifier.set("fat")
        val jvmJar = named<org.gradle.jvm.tasks.Jar>("jvmJar").get()
        from(jvmJar.archiveFile)
        configurations.add(project.configurations.named("jvmRuntimeClasspath").get())
    }
}

旧解决方案:

application {
    mainClass.set(theMainClass)
}

tasks {
    val shadowCreate by creating(com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar::class) {
        manifest { attributes["Main-Class"] = theMainClass }
        archiveClassifier.set("fat")
        mergeServiceFiles()
        from(kotlin.jvm().compilations.getByName("main").output)
        configurations = mutableListOf(kotlin.jvm().compilations.getByName("main").compileDependencyFiles as Configuration)
    }
    val build by existing {
        dependsOn(shadowCreate)
    }
}

但现在我正在努力研究如何让应用程序 gradle run 任务和影子 gradle runShadow 任务正确执行。

有人有任何想法 (kotlindsl) 吗?

我正在使用以下内容:

tasks.named<JavaExec>("run") {
    classpath += objects.fileCollection().from(
        tasks.named("compileKotlinJvm"),
        configurations.named("jvmRuntimeClasspath")
    )
}