问题描述
我有一个Kotlin Gradle项目,我想在jar文件中包含Kotlin的运行时和stdlib。我正在使用它,但是当我使用build.gradle配置来构建项目时,它不包括运行时或stdlib。
I have a Kotlin Gradle project, and I would like to include Kotlin's runtime and stdlib in the jar file. I'm currently using this, but it's not including the runtime or stdlib when I build the project using the build.gradle configuration.
compileKotlin {
kotlinOptions {
includeRuntime = true
noStdlib = false
}
}
这是我用来在jar中包含runtime / stdlib的Gradle代码,但它不像我预期的那样工作。下面是一些上下文的完整build.gradle文件:
This is the Gradle code I'm using to include the runtime/stdlib in the jar, but it isn't working like I expect it to. Here's the full build.gradle file for some context:https://github.com/BenWoodworth/CrossPlatformGreeter/blob/bd1da79f36e70e3d88ed871bc35502ecc3a852fb/build.gradle#L35-L43
Kotlin的Gradle文档似乎表明将kotlinOptions.includeRuntime设置为true应在结果.jar中包含Kotlin运行时。
Kotlin's Gradle documentation seems to indicate that setting kotlinOptions.includeRuntime to true should include the Kotlin runtime in the resulting .jar.
https://kotlinlang.org/docs/reference/using-gradle.html#attributes-specific-for-kotlin
编辑:
这可能是相关的。当我运行compileKotlin时,我收到了一些与运行时相关的警告:
This might be related. When I run compileKotlin, I'm getting a couple of warnings related to the runtime:
:compileKotlin
w: Classpath entry points to a non-existent location: <no_path>\lib\kotlin-runtime.jar
BUILD SUCCESSFUL
推荐答案
这是我想出的另一种选择。它会使用jar任务将Kotlin运行时和stdlib添加到jar。
Here's an alternative I came up with. It'll add the Kotlin runtime and stdlib to the jar using the jar task.
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) }
}
}
这篇关于Gradle compileKotlin includeRuntime不向jar添加运行时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!