Exception in thread "main" java.util.concurrent.ExecutionException: java.lang.NoClassDefFoundError: Could not initialize class org.jetbrains.kotlin.com.intellij.pom.java.LanguageLevel
at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122
at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:191)
at com.pinterest.ktlint.KtlintCommandLine.parallel(Main.kt:575)
at com.pinterest.ktlint.KtlintCommandLine.parallel$default(Main.kt:547)
at com.pinterest.ktlint.KtlintCommandLine.lintFiles(Main.kt:298)
at com.pinterest.ktlint.KtlintCommandLine.run(Main.kt:262)
at com.pinterest.ktlint.Main.main(Main.kt:70)
Caused by: 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:121)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.createForProduction(KotlinCoreEnvironment.kt:425)
at com.pinterest.ktlint.core.internal.KotlinPsiFileFactory.initializePsiFileFactory(KotlinPsiFileFactory.kt:74)
at com.pinterest.ktlint.core.internal.KotlinPsiFileFactory.acquirePsiFileFactory$ktlint_core(KotlinPsiFileFactory.kt:39)
at com.pinterest.ktlint.core.KtLint.format(KtLint.kt:378)
at com.pinterest.ktlint.internal.FileUtilsKt.formatFile(FileUtils.kt:182)
at com.pinterest.ktlint.KtlintCommandLine.process(Main.kt:366)
at com.pinterest.ktlint.KtlintCommandLine.access$process(Main.kt:89)
at com.pinterest.ktlint.KtlintCommandLine$lintFiles$3$1.call(Main.kt:289)
at com.pinterest.ktlint.KtlintCommandLine$lintFiles$3$1.call(Main.kt:288)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
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)
For those using the Gradle Kotlin DSL, I was able to invoke the formatter without issues with JDK 17 by doing the following:
The most important part here is adding:
0.46.1 still not working
I think this bug is still not fixed. In case the linter has to fix some linting issues there is still an exception
module java.base does not "opens java.lang" to unnamed module
.Any news about this?
For maven projects using the
maven-antrun-plugin
you can add this to your pom:It worked for me by adding the following line to
.mvn/jvm.config
--add-opens java.base/java.lang=ALL-UNNAMED
I am using ktlint with Gradle wrapper (without a plugin) with Gradle 7.1.1 I upgraded to Kotlin 1.5.21 and ktlint 0.42.1 now, but get this error now instead:
when running ./gradlew ktlintFormat:
Java 17-temurin ktlint still not working with following command
mvn ktlint:format -DjvmArgs=“–add-opens java.base/java.lang=ALL-UNNAMED” -DjvmArgs=" --add-exports java.base/sun.nio.ch=ALL-UNNAMED"
Error: Unable to make field private transient java.lang.Object java.lang.Throwable.backtrace accessible: module java.base does not “opens java.lang” to unnamed module
I have the same version combination and the same failure happens.
You could try to run KtLint with
--add-opens "java.base/java.util=ALL-UNNAMED" --add-exports="java.base/sun.nio.ch=ALL-UNNAMED"
arguments.