失败:生成失败,发生异常。
无法确定任务':packageJson'的依赖关系。
Could not resolve all dependencies for configuration ':npm'. Could not resolve org.jetbrains.kotlinx:kotlinx-datetime:0.1.0. Required by: project : > Cannot choose between the following variants of org.jetbrains.kotlinx:kotlinx-datetime:0.1.0: - jsIr-runtime - jsLegacy-runtime All of them match the consumer attributes: - Variant 'jsIr-runtime' capability org.jetbrains.kotlinx:kotlinx-datetime:0.1.0: - Unmatched attributes: - Found org.gradle.status 'release' but wasn't required. - Found org.jetbrains.kotlin.js.compiler 'ir' but wasn't required. - Compatible attributes: - Required org.gradle.usage 'kotlin-runtime' and found compatible value 'kotlin-runtime'. - Required org.jetbrains.kotlin.platform.type 'js' and found compatible value 'js'. - Variant 'jsLegacy-runtime' capability org.jetbrains.kotlinx:kotlinx-datetime:0.1.0: - Unmatched attributes: - Found org.gradle.status 'release' but wasn't required. - Found org.jetbrains.kotlin.js.compiler 'legacy' but wasn't required. - Compatible attributes: - Required org.gradle.usage 'kotlin-runtime' and found compatible value 'kotlin-runtime'. - Required org.jetbrains.kotlin.platform.type 'js' and found compatible value 'js'.
使用--stacktrace选项运行以获取堆栈跟踪。使用--info或--debug选项运行,以获取更多日志输出。与--scan一起运行以获取完整的见解。
7秒内失败
将构建扫描发布到scans.gradle.com要求接受https://gradle.com/terms-of-service定义的Gradle服务条款。您接受这些条款吗? [是,不是]
最佳答案
使用Kotlin 1.3.xx构建项目时,如果其中一个依赖项(或任何传递性依赖项)是使用Kotlin 1.4+构建的,则可能会遇到Gradle错误:
之所以出现此解决问题,是因为Kotlin 1.4引入了Kotlin / JS的两个不同编译器后端之间的选择– Kotlin 1.3.xx中不提供这种选择。
解决方法:
为了使用这些库,请在项目的根目录中创建一个名为workaround_to_use_1_4_libs_in_1_3.gradle.kts的文件,并添加以下代码:
val pluginAction: Plugin<*>.() -> Unit = {
val pluginVersion = try {
this.javaClass.getMethod("getKotlinPluginVersion").invoke(this) as String
} catch(e: Exception) { null }
if (pluginVersion != null && pluginVersion.startsWith("1.3")) {
val jsCompilerAttr = Attribute.of("org.jetbrains.kotlin.js.compiler", String::class.java)
project.dependencies.attributesSchema.attribute(jsCompilerAttr) {
this.disambiguationRules.add(KotlinJsCompilerDisambiguationRule::class.java)
}
}
}
project.plugins.withId("org.jetbrains.kotlin.multiplatform", pluginAction)
project.plugins.withId("org.jetbrains.kotlin.js", pluginAction)
// project.plugins.withId("kotlin2js", pluginAction) // maybe even `kotlin2js`
private class KotlinJsCompilerDisambiguationRule : AttributeDisambiguationRule<String> {
override fun execute(details: MultipleCandidatesDetails<String>) {
details.closestMatch("legacy")
}
}
要应用解决方法,请将以下代码段添加到build.gradle文件中:apply(from = "workaround_to_use_1_4_libs_in_1_3.gradle.kts")
我没有在闲置 channel 中找到某个人指出的解决方案您跟踪具有解决方案的链接
the sloution link
关于gradle - 在kotlin js项目中包含kotlinx-datetime库的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63415127/