Gradle compileKotlin includeRuntime不向jar添加运行时

Ben*_*rth 5 runtime jar std gradle kotlin

我有一个Kotlin Gradle项目,我想将Kotlin的运行时和stdlib包含在jar文件中.我目前正在使用它,但是当我使用build.gradle配置构建项目时,它不包括运行时或stdlib.

compileKotlin {
    kotlinOptions {
        includeRuntime = true
        noStdlib = false
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我用来在jar中包含运行时/ stdlib的Gradle代码,但它不像我期望的那样工作.以下是某些上下文的完整build.gradle文件:https: //github.com/BenWoodworth/CrossPlatformGreeter/blob/bd1da79f36e70e3d88ed871bc35502ecc3a852fb/build.gradle#L35-L43

Kotlin的Gradle文档似乎表明将kotlinOptions.includeRuntime设置为true应该在生成的.jar中包含Kotlin运行时.
https://kotlinlang.org/docs/reference/using-gradle.html#attributes-specific-for-kotlin

编辑: 这可能是相关的.当我运行compileKotlin时,我收到了一些与运行时相关的警告:

:compileKotlin
w: Classpath entry points to a non-existent location: <no_path>\lib\kotlin-runtime.jar

BUILD SUCCESSFUL
Run Code Online (Sandbox Code Playgroud)

Ben*_*rth 3

这是我想出的一个替代方案。它将使用 jar 任务将 Kotlin 运行时和 stdlib 添加到 jar 中。

jar {
    from {
        String[] include = [
            "kotlin-runtime-${version_kotlin}.jar",
            "kotlin-stdlib-${version_kotlin}.jar"
        ]

        configurations.compile
                .findAll { include.contains(it.name) }
                .collect { it.isDirectory() ? it : zipTree(it) }
    }
}
Run Code Online (Sandbox Code Playgroud)