gpt4 book ai didi

Gradle compileKotlin includeRuntime 不向 jar 添加运行时

转载 作者:行者123 更新时间:2023-12-04 21:34:18 24 4
gpt4 key购买 nike

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

compileKotlin {
kotlinOptions {
includeRuntime = true
noStdlib = false
}
}

这是我用来在 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

最佳答案

这是我想出的替代方案。它将使用 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) }
}
}

关于Gradle compileKotlin includeRuntime 不向 jar 添加运行时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42429289/

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