I trying to run simple plugin from cli. My interpr...
# compiler
m
I trying to run simple plugin from cli. My interpretation of docs is like this
kotlinc hello.kt -include-runtime -Xplugin=kotlin-ir-plugin-0.1.0-SNAPSHOT.jar -Xuse-ir -d hello.jar
But I am gettng error
Copy code
java.lang.IllegalStateException: The provided plugin com.bnorm.template.TemplateComponentRegistrar is not compatible with this version of compiler
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.registerExtensionsFromPlugins$cli(KotlinCoreEnvironment.kt:592)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$ProjectEnvironment.registerExtensionsFromPlugins(KotlinCoreEnvironment.kt:132)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.<init>(KotlinCoreEnvironment.kt:172)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.<init>(KotlinCoreEnvironment.kt)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.createForProduction(KotlinCoreEnvironment.kt:426)
	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.cli.common.CLITool.exec(CLITool.kt:76)
	at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:45)
	at org.jetbrains.kotlin.cli.common.CLITool$Companion.doMainNoExit(CLITool.kt:227)
	at org.jetbrains.kotlin.cli.common.CLITool$Companion.doMainNoExit$default(CLITool.kt:222)
	at org.jetbrains.kotlin.cli.common.CLITool$Companion.doMain(CLITool.kt:214)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler$Companion.main(K2JVMCompiler.kt:271)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.main(K2JVMCompiler.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:566)
	at org.jetbrains.kotlin.preloading.Preloader.run(Preloader.java:87)
	at org.jetbrains.kotlin.preloading.Preloader.main(Preloader.java:44)
Caused by: java.lang.AbstractMethodError: Receiver class com.bnorm.template.TemplateComponentRegistrar 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:584)
	... 23 more
Jar file for plugin has been built with gradle from template project by @bnorm https://blog.bnorm.dev/writing-your-second-compiler-plugin-part-1 and units tests are runnign as expected.
If I do the same with a compiler-plugin jar from a module for Kotlin native, it works, plugins gets loaded and makes nice dumps 🙂 I am confused, how can I tell to kotlinc to be a jvm compiler not Kotlin/native.A result of compilation is jar file with I can run with
java -jar hello.jar
. I am almost sure, that Kotlin/native is even not installed, I am using dockerized kotlinc downloaded directly from github releae page...
r
I'm assuming
kotlinc -version
matches the compiler dependency of your plugin? That would be my first guess
You can also use
kotlinc-jvm
to force jvm backend (it should be default though, afaik)
m
The first error message suggests that it could be because of different compiler versions, but Kotlin/Native variants built the same way works, I would expect none of them working. I also also experimented with Java versions. AFAIK, one of the differences between Kotlin-jvm and Kotlin/native which are quite well described in the mentioned blog, is a package name for
MockProject
which in the second error on bottom in my stack trace
r
Yeah, but if I remember right, they matched at some point, but then JVM changed and native didn't, so you would see the same (or at least similar) error on an old JVM backend. It's more of a "first thing to check", anyways, the only other thing I can think of is that the template doesn't specify a
kotlin-compiler-embeddable
version, which (I think) picks it up from the build plugin, so make sure your CLI is 1.4.30.
👍 1