我是Gradle的新手,但最近我想在一个项目中使用Kotlin-Jupyter笔记本。
我按照指示,我克隆了repo在https://github.com/Kotlin/kotlin-jupyter...
在我的整个奋斗过程中,我经历了5、6个错误,所有这些错误都花了几天时间才修复。
我在键入命令gradlew install
时收到此新错误,这是一个内部异常:
> Task :kotlin-jupyter-publish:compileKotlin FAILED
The `kotlin-dsl` plugin applied to project ':kotlin-jupyter-publish' enables experimental Kotlin compiler features. For more information see https://docs.gradle.org/6.8.2/userguide/kotlin_dsl.html#sec:kotlin-dsl_plugin
e: java.lang.NoClassDefFoundError: Could not initialize class org.jetbrains.kotlin.com.intellij.pom.java.LanguageLevel
at org.jetbrains.kotlin.com.intellij.core.CoreLanguageLevelProjectExtension.<init>(CoreLanguageLevelProjectExtension.java:26)
at org.jetbrains.kotlin.com.intellij.core.JavaCoreProjectEnvironment.<init>(JavaCoreProjectEnvironment.java:42)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreProjectEnvironment.<init>(KotlinCoreProjectEnvironment.kt:26)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$ProjectEnvironment.<init>(KotlinCoreEnvironment.kt:118)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.createForProduction(KotlinCoreEnvironment.kt:420)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.createCoreEnvironment(K2JVMCompiler.kt:226)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:152)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:52)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:88)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:44)
at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:98)
at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:371)
at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:105)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileIncrementally(IncrementalCompilerRunner.kt:249)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.access$compileIncrementally(IncrementalCompilerRunner.kt:38)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner$compile$2.invoke(IncrementalCompilerRunner.kt:80)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compile(IncrementalCompilerRunner.kt:92)
at org.jetbrains.kotlin.daemon.CompileServiceImplBase.execIncrementalCompiler(CompileServiceImpl.kt:602)
at org.jetbrains.kotlin.daemon.CompileServiceImplBase.access$execIncrementalCompiler(CompileServiceImpl.kt:93)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1644)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357)
at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:691)
at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:587)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:828)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:705)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:704)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
at java.base/java.lang.Thread.run(Thread.java:831)
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':kotlin-jupyter-publish:compileKotlin'.
> Internal compiler error. See log for more details
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s
是的,它很长。我不确定错误的原因是什么-坦白说,我是Gradle的初学者。我想知道为什么会出现此错误,以及如何修复此错误。
同样,就在最近我安装了JDK并为JDK设置了环境变量。我不确定错误是否因此而出现,如果是的话-这是我的环境变量,也许我设置错了:C:\Program Files\Java\jdk-16
这也是gradle属性文件:
# kotlinVersion=1.4.255-SNAPSHOT
kotlinVersion=1.4.31
kotlinLanguageLevel=1.4
jvmTarget=1.8
shadowJarVersion=5.2.0
kotlinxSerializationVersion=1.1.0
ktlintGradleVersion=9.4.1
ktlintVersion=0.40.0
junitVersion=5.6.2
slf4jVersion=1.7.30
khttpVersion=1.0.0
http4kVersion=4.4.0.1
artifactsPath=build/artifacts
baseVersion=0.8.3
projectRepoUrl=https://github.com/Kotlin/kotlin-jupyter
docsRepo=git@github.com:ileasile/kotlin-jupyter-docs.git
pushRepoUrl=git@github.com:Kotlin/kotlin-jupyter.git
jupyterApiVersion=0.8.3.291
kotlin.jupyter.add.api=false
kotlin.jupyter.add.scanner=false
org.gradle.jvmargs=-Xmx512M
同时构建.gradle文件:
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlinx.jupyter.build.getFlag
import org.jetbrains.kotlinx.jupyter.plugin.options
import org.jetbrains.kotlinx.jupyter.publishing.addPublication
import org.jetbrains.kotlinx.jupyter.publishing.applyNexusPlugin
import org.jlleitschuh.gradle.ktlint.KtlintExtension
plugins {
kotlin("jvm")
kotlin("jupyter.api") apply false
kotlin("plugin.serialization")
id("com.github.johnrengelman.shadow")
id("org.jlleitschuh.gradle.ktlint")
id("org.jetbrains.kotlinx.jupyter.dependencies")
id("org.jetbrains.kotlinx.jupyter.publishing")
id("org.jetbrains.kotlinx.jupyter.doc")
}
extra["isMainProject"] = true
val kotlinxSerializationVersion: String by project
val ktlintVersion: String by project
val junitVersion: String by project
val slf4jVersion: String by project
val khttpVersion: String by project
val docsRepo: String by project
val taskOptions = project.options()
val deploy: Configuration by configurations.creating
deploy.apply {
exclude("org.jetbrains.kotlinx", "kotlinx-serialization-json-jvm")
exclude("org.jetbrains.kotlinx", "kotlinx-serialization-core-jvm")
}
applyNexusPlugin()
fun KtlintExtension.setup() {
version.set(ktlintVersion)
enableExperimentalRules.set(true)
}
ktlint {
setup()
}
subprojects {
apply(plugin = "org.jlleitschuh.gradle.ktlint")
ktlint {
setup()
}
}
allprojects {
val kotlinLanguageLevel: String by rootProject
val jvmTarget: String by rootProject
tasks.withType(KotlinCompile::class.java).all {
kotlinOptions {
languageVersion = kotlinLanguageLevel
this.jvmTarget = jvmTarget
}
}
}
dependencies {
// Dependency on module with compiler.
api(project(":shared-compiler"))
// Standard dependencies
implementation(kotlin("stdlib"))
implementation(kotlin("reflect"))
implementation(kotlin("stdlib-jdk8"))
implementation("org.jetbrains:annotations:20.1.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2")
// Embedded compiler and scripting dependencies
implementation(kotlin("compiler-embeddable"))
implementation(kotlin("scripting-compiler-impl-embeddable"))
implementation(kotlin("scripting-compiler-embeddable"))
implementation(kotlin("scripting-ide-services"))
implementation(kotlin("main-kts"))
implementation(kotlin("script-util"))
implementation(kotlin("scripting-common"))
// Embedded version of serialization plugin for notebook code
implementation(kotlin("serialization"))
// Logging
implementation("org.slf4j:slf4j-api:$slf4jVersion")
runtimeOnly("org.slf4j:slf4j-simple:$slf4jVersion")
// ZeroMQ library for implementing messaging protocol
implementation("org.zeromq:jeromq:0.5.2")
// Clikt library for parsing output magics
implementation("com.github.ajalt:clikt:2.8.0")
// Serialization implementation for kernel code
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlinxSerializationVersion")
// Test dependencies: kotlin-test and Junit 5
testImplementation(kotlin("test"))
testImplementation("org.junit.jupiter:junit-jupiter-api:$junitVersion")
testImplementation("io.kotlintest:kotlintest-assertions:3.1.6")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$junitVersion")
deploy(project(":lib"))
deploy(project(":api"))
deploy(kotlin("script-runtime"))
}
tasks.register("publishLocal") {
group = "publishing"
dependsOn(
tasks.condaPackage,
tasks.pyPiPackage
)
}
tasks.named("closeRepository") {
mustRunAfter("publishToSonatype")
}
tasks.register("publishToSonatypeAndRelease") {
group = "publishing"
dependsOn("publishToSonatype", "closeAndReleaseRepository")
}
tasks.register("publishToPluginPortal") {
group = "publishing"
dependsOn(
":kotlin-jupyter-api-gradle-plugin:publishPlugins"
)
}
tasks.jar {
manifest {
attributes["Main-Class"] = taskOptions.mainClassFQN
attributes["Implementation-Version"] = project.version
}
}
tasks.shadowJar {
archiveBaseName.set(taskOptions.packageName)
archiveClassifier.set("")
mergeServiceFiles()
manifest {
attributes(tasks.jar.get().manifest.attributes)
}
}
tasks.test {
val doParallelTesting = getFlag("test.parallel", true)
/**
* Set to true to debug classpath/shadowing issues, see testKlaxonClasspathDoesntLeak test
*/
val useShadowedJar = getFlag("test.useShadowed", false)
useJUnitPlatform()
testLogging {
events("passed", "skipped", "failed")
}
if (useShadowedJar) {
dependsOn(tasks.shadowJar.get())
classpath = files(tasks.shadowJar.get()) + classpath
}
systemProperties = mutableMapOf(
"junit.jupiter.displayname.generator.default" to "org.junit.jupiter.api.DisplayNameGenerator\$ReplaceUnderscores",
"junit.jupiter.execution.parallel.enabled" to doParallelTesting.toString() as Any,
"junit.jupiter.execution.parallel.mode.default" to "concurrent",
"junit.jupiter.execution.parallel.mode.classes.default" to "concurrent"
)
}
tasks.processResources {
dependsOn(tasks.buildProperties)
}
tasks.check {
dependsOn(tasks.checkReadme)
}
tasks.publishDocs {
docsRepoUrl.set(docsRepo)
}
addPublication {
publicationName = "kernel"
artifactId = "kotlin-jupyter-kernel"
description = "Kotlin Jupyter kernel published as artifact"
packageName = artifactId
}
5条答案
按热度按时间isr3a4wc1#
我在 Android Studio 上遇到了完全相同的问题,并通过将KotlinGradle插件从版本1.4.31更新为版本1.5.30解决了该问题。
在我的项目级 build.gradle 文件中。
7rtdyuoh2#
不确定这是否是同一个问题,但对我来说,向
gradle.properties
添加以下行解决了这个问题y3bcpkx13#
使用JDK 16以外的版本(我使用的是JDK 15)应该可以解决这个问题。另外,确保更改所有环境变量并重新启动正在使用的命令行。
xmjla07d4#
在react native上,我必须添加以下内容来修复它:
在
android/build.gradle
中,在classpath("com.android.tools.build:gradle:7.1.1")
之后,在buildscript.dependencies
下xxls0lw85#
在通过Gradle构建intellij插件时遇到了类似的问题。解决方案是从主目录的
.gradle
中删除cache
文件夹中的所有内容。