Kotlin Internal Error java.lang.IllegalStateException with Jetbrains Compose - kotlin

Hi I'm new to kotlin and trying to get a Jetpack compose desktop calculator application up and running. I wrote some JUnit tests and attempted to run them, but I am met with an internal error instead. This is the IntelliJ output:
Kotlin: [Internal Error] java.lang.IllegalStateException: The provided plugin androidx.compose.compiler.plugins.kotlin.ComposeComponentRegistrar is not compatible with this version of compiler
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.registerExtensionsFromPlugins$cli(KotlinCoreEnvironment.kt:618)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$ProjectEnvironment.registerExtensionsFromPlugins(KotlinCoreEnvironment.kt:130)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.<init>(KotlinCoreEnvironment.kt:170)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.<init>(KotlinCoreEnvironment.kt)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.createForProduction(KotlinCoreEnvironment.kt:431)
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:92)
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.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1500)
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)
Caused by: java.lang.AbstractMethodError: Receiver class androidx.compose.compiler.plugins.kotlin.ComposeComponentRegistrar does not define or inherit an implementation of the resolved method 'abstract void registerProjectComponents(com.intellij.mock.MockProject, org.jetbrains.kotlin.config.CompilerConfiguration)' of interface org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar.
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.registerExtensionsFromPlugins$cli(KotlinCoreEnvironment.kt:610)
... 28 more
I've spent a few hours trying to get the right dependencies in my build.gradle.kts file. Right now I have:
dependencies {
kotlinCompilerClasspath("com.android.tools.build:gradle:7.0.0-alpha02")
implementation(compose.desktop.currentOs)
implementation("org.junit.jupiter:junit-jupiter:5.8.1")
kotlinCompilerClasspath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21")
}
Another post suggested using Compose version 1.0.0-beta08, which I tried and got:
Plugin [id: 'org.jetbrains.compose', version: '1.0.0-beta08'] was not found in any of the following sources:
with no further information. 1.0.0-alpha3 has been the only version to successfully build. If you have thoughts on this, let me know, else I can ask it in a new question.
I'm running Kotlin 1.5.21, Jetbrains Compose version 1.0.0-alpha3 and I have the maven repository set to "https://maven.pkg.jetbrains.space/public/p/compose/dev" as is recommended in several forums. If you have any resources I may check out, or know of a fix, I feel as though I've exhausted my options -- please leave me a comment, thanks.

Related

Shaddow Jar missing some Vert.x classes from dependecies

I have successfully created a shadow-jar with few verticles using Kotlin coroutines extension and able to run them via vertx run command line while specifying the path to my jar except a verticle that on its start-up creates a telnet shell with exception:
java.lang.NoClassDefFoundError: io.vertx.ext.shell.term.TelnetTermOptions
at io.vertx.kotlin.ext.shell.term.TelnetTermOptionsKt.telnetTermOptionsOf(TelnetTermOptions.kt:119)
at io.vertx.kotlin.ext.shell.term.TelnetTermOptionsKt.telnetTermOptionsOf$default(TelnetTermOptions.kt:119)
at **********************.ContactsReceiver.start(ContactsReceiver.kt:20)
at io.vertx.kotlin.coroutines.CoroutineVerticle$start$1.invokeSuspend(CoroutineVerticle.kt:53)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:238)
at io.vertx.kotlin.coroutines.VertxCoroutineExecutor.execute(VertxCoroutine.kt:214)
at kotlinx.coroutines.ExecutorCoroutineDispatcherBase.dispatch(Executors.kt:64)
at kotlinx.coroutines.DispatchedKt.resumeCancellable(Dispatched.kt:413)
at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:25)
at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:109)
at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:154)
at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:54)
at kotlinx.coroutines.BuildersKt.launch(Unknown Source)
at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default(Builders.common.kt:47)
at kotlinx.coroutines.BuildersKt.launch$default(Unknown Source)
at io.vertx.kotlin.coroutines.CoroutineVerticle.start(CoroutineVerticle.kt:51)
at io.vertx.core.Verticle.start(Verticle.java:66)
at io.vertx.core.impl.DeploymentManager.lambda$doDeploy$8(DeploymentManager.java:556)
at io.vertx.core.impl.DeploymentManager$$Lambda$126.0000000063922220.handle(Unknown Source)
at io.vertx.core.impl.ContextImpl.executeTask(ContextImpl.java:369)
at io.vertx.core.impl.EventLoopContext.lambda$executeAsync$0(EventLoopContext.java:38)
at io.vertx.core.impl.EventLoopContext$$Lambda$127.0000000060DA8B00.run(Unknown Source)
at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:510)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:518)
at io.netty.util.concurrent.SingleThreadEventExecutor$6.run(SingleThreadEventExecutor.java:1044)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base/java.lang.Thread.run(Thread.java:831)
My project is built using Gradle (Kotlin DSL)
These are my vert.x dependencies:
io.vertx:vertx-core
io.vertx:vertx-lang-kotlin
io.vertx:vertx-lang-kotlin-coroutines
io.vertx:vertx-shell
io.vertx:vertx-auth-shiro
io.vertx:vertx-tcp-eventbus-bridge
And my shadow jar task configered like so:
tasks.withType<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar> {
classifier = "fat"
isPreserveFileTimestamps = false
isReproducibleFileOrder = true
minimize()
manifest {
attributes["Main-Verticle"] = vertx.mainVerticle
}
mergeServiceFiles {
include("META-INF/services/io.vertx.core.spi.VerticleFactory")
}
}
Seems like minimize() is not the issue but what is important that if I deploy that verticle programatically from the main function evrything works fine and I got the telnet shell.
Perhaps I missing something in my manifest configuration on the shadow jar task?
I had a remotely similar issues with the HoconProcessor (here), but in the mean time more relevantly, also with the class GraphiQLHandlerOptions, of which I imported a deprecated version (look), causing the class to be included in the jar under the same name, but its use expectedly throwing java.lang.NoClassDefFoundError.
Since TelnetTermOptions is such an options class too, maybe it suffered from a similar deprecation recently. Hope this helps/inspires.

Can't get basic Kotlin coroutine examples to work in Windows console

I'm experimenting with Kotlin. Testing via Android is slow and fiddly so I'm trying to just using the Windows console version. This seems to be less well documented.
Basic hello world worked fine so I moved onto the first coroutine example:
import kotlinx.coroutines.*
fun main() {
GlobalScope.launch {
delay(1000L)
println("World!")
}
println("Hello,")
Thread.sleep(2000L)
}
I'm using Kotlin 1.3.50 and I downloaded kotlinx-coroutines-core-1.3.0.jar and put it in the same directly as my soucre file.
I build it with:
kotlinc kotlintest.kt -cp kotlinx-coroutines-core-1.3.0.jar -include-runtime
I attempt to run it with:
kotlin KotlintestKt
I get this error output:
Exception in thread "main" java.lang.NoClassDefFoundError: kotlinx/coroutines/GlobalScope
at KotlintestKt.main(kotlintest.kt:4)
at KotlintestKt.main(kotlintest.kt)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at org.jetbrains.kotlin.runner.AbstractRunner.run(runners.kt:61)
at org.jetbrains.kotlin.runner.Main.run(Main.kt:110)
at org.jetbrains.kotlin.runner.Main.main(Main.kt:120)
Caused by: java.lang.ClassNotFoundException: kotlinx.coroutines.GlobalScope
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:436)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 9 more
There are similar questions but answers seem to only go into Gradle or IntelliJ IDEA, which I'm not using. I have basically no prior experience with Java or Kotlin but decades of hobby programming experience.

SerializationComponentRegistrar is not compatible with this version of compiler

I am getting this error inside AS - even though I tripple checked to pick a valid version pairing (kotlin 1.2.40 with serialisation 0.5.0):
Error:Kotlin: [Internal Error] java.lang.IllegalStateException: The provided plugin org.jetbrains.kotlinx.serialization.compiler.extensions.SerializationComponentRegistrar is not compatible with this version of compiler
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.<init>(KotlinCoreEnvironment.kt:186)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.<init>(KotlinCoreEnvironment.kt:119)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.createForProduction(KotlinCoreEnvironment.kt:418)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.createCoreEnvironment(K2JVMCompiler.kt:265)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:154)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:63)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:107)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:51)
at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:96)
at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$$inlined$ifAlive$lambda$1.invoke(CompileServiceImpl.kt:399)
at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$$inlined$ifAlive$lambda$1.invoke(CompileServiceImpl.kt:98)
at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:920)
at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:98)
at org.jetbrains.kotlin.daemon.common.DummyProfiler.withMeasure(PerfUtils.kt:137)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.checkedCompile(CompileServiceImpl.kt:950)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.doCompile(CompileServiceImpl.kt:919)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:397)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:361)
at sun.rmi.transport.Transport$1.run(Transport.java:200)
at sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.AbstractMethodError: org.jetbrains.kotlinx.serialization.compiler.extensions.SerializationComponentRegistrar.registerProjectComponents(Lcom/intellij/mock/MockProject;Lorg/jetbrains/kotlin/config/CompilerConfiguration;)V
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.<init>(KotlinCoreEnvironment.kt:184)
... 33 more
Check your installed Kotlin plugin in the idea(Tools>Kotlin>Configure Kotlin Plugin Updates). Must be same as in your build.gradle file.
There's an IntelliJ / Android Studio plugin that's made just for the Kotlin Serialization support, separate from the main Kotlin plugin. From the Working in IntelliJ IDEA section of the readme:
Because serialization is still highly experimental, it is shipped as a separate artifact from "big" Kotlin IDEA plugin. You can download additional IDEA plugin for working with projects that uses serialization from its TeamCity build page
It provides links to the latest TeamCity builds for this plugin, including this one for Kotlin 1.2.40.
Since they only currently publish this plugin through TeamCity, you would have to install it manually by going to Preferences > Plugins > Install plugin from disk...
For anyone using IntelliJ instead of Android Studio, if the plugin doesn't solve the problem, the same readme says to:
try to use gradle for running builds: Settings - Build, Execution, Deployment - Build Tools - Gradle - Runner - tick Delegate IDE build/run actions to gradle; or launch builds from console.
There's an open ticket on Github about this error message, and it might also be worth keeping an eye on that.

Spring boot will not run in InteliJ [duplicate]

Recently I created a new project using IntelliJ IDEA and Gradle for dependency management. After resolving all the dependencies needed by the project and running it I get the following error:
java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication
at com.some.fancy.name.Application.main(Application.java:13)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 6 more
The problem occurs only with the classes from the resolved dependencies (I tried it also with a simple main program using Cache from Guava). The class causing the error is the following:
#SpringBootApplication
public class Application {
public static void main(String... args) {
SpringApplication.run(Application.class, args);
}
}
All the fields are shown correct colour (annotations are yellow, nothing is red), IntelliJ has all the resolved dependencies in the External Libraries directory. I'm using the green "run" arrow to start the project.
When using gradle from the command line, creating a fat jar then everything works fine. I already tried "Invalidate Caches/Restart", pulled the project several times from the repository, cleared the gradle caches, removed all the dependencies by hand, tried to run it using the Community Edition, the Ultimate Edition, running older projects which already worked some time ago (and don't work now).
Could it be somehow related to updating IntelliJ IDEA to 2016.3.4, build 163.12024.16?
It's a known issue in IntelliJ IDEA that is specific to Gradle 3.4 and later versions:
IDEA-167412 Gradle 3.4-rc-1 changes compile dependencies to provided
original bug report in the Gradle project with more details
comment from the responsible developer regarding "Create Module per source set" option and how Gradle integration works in IntelliJ IDEA
It's already fixed in IntelliJ IDEA 2017.1 and 2016.3.6.
You can also use Gradle 3.3 or older as a workaround if you can't or don't want to update IntelliJ IDEA.
I had the same problem, getting the error below from a spring boot application which was working fine a day before. I am using IntelliJ 2020.3, Gradle 6.5.1. I suspect my repository might have been corrupted.
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication
After lot of tries from my IntelliJ I tried bootRun (in the gradle tree you can find this under Tasks > application > bootRun) and it worked.
Setting gradle version to 3.3 corrected this issue.

NoClassDefFoundError after IntelliJ IDEA upgrade

Recently I created a new project using IntelliJ IDEA and Gradle for dependency management. After resolving all the dependencies needed by the project and running it I get the following error:
java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication
at com.some.fancy.name.Application.main(Application.java:13)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 6 more
The problem occurs only with the classes from the resolved dependencies (I tried it also with a simple main program using Cache from Guava). The class causing the error is the following:
#SpringBootApplication
public class Application {
public static void main(String... args) {
SpringApplication.run(Application.class, args);
}
}
All the fields are shown correct colour (annotations are yellow, nothing is red), IntelliJ has all the resolved dependencies in the External Libraries directory. I'm using the green "run" arrow to start the project.
When using gradle from the command line, creating a fat jar then everything works fine. I already tried "Invalidate Caches/Restart", pulled the project several times from the repository, cleared the gradle caches, removed all the dependencies by hand, tried to run it using the Community Edition, the Ultimate Edition, running older projects which already worked some time ago (and don't work now).
Could it be somehow related to updating IntelliJ IDEA to 2016.3.4, build 163.12024.16?
It's a known issue in IntelliJ IDEA that is specific to Gradle 3.4 and later versions:
IDEA-167412 Gradle 3.4-rc-1 changes compile dependencies to provided
original bug report in the Gradle project with more details
comment from the responsible developer regarding "Create Module per source set" option and how Gradle integration works in IntelliJ IDEA
It's already fixed in IntelliJ IDEA 2017.1 and 2016.3.6.
You can also use Gradle 3.3 or older as a workaround if you can't or don't want to update IntelliJ IDEA.
I had the same problem, getting the error below from a spring boot application which was working fine a day before. I am using IntelliJ 2020.3, Gradle 6.5.1. I suspect my repository might have been corrupted.
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication
After lot of tries from my IntelliJ I tried bootRun (in the gradle tree you can find this under Tasks > application > bootRun) and it worked.
Setting gradle version to 3.3 corrected this issue.