Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KSP plugin works fine when compiling with gradle but fails when compiling with Intellij IDEA #969

Open
aduchate opened this issue Apr 28, 2022 · 15 comments

Comments

@aduchate
Copy link

aduchate commented Apr 28, 2022

The very simple project here demonstrates the issue:

https://github.com/aduchate/kmap-test

When compiled using gradle, everything goes fine but when compiled using IntelliJ, the following error occurs

Kotlin: [Internal Error] java.lang.IllegalStateException: The provided plugin com.google.devtools.ksp.KotlinSymbolProcessingComponentRegistrar is not compatible with this version of compiler
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.registerExtensionsFromPlugins$cli(KotlinCoreEnvironment.kt:667)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$ProjectEnvironment.registerExtensionsFromPlugins(KotlinCoreEnvironment.kt:169)
...
  at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.AbstractMethodError: Receiver class com.google.devtools.ksp.KotlinSymbolProcessingComponentRegistrar does not define or inherit an implementation of the resolved method abstract registerProjectComponents(Lcom/intellij/mock/MockProject;Lorg/jetbrains/kotlin/config/CompilerConfiguration;)V of interface org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar.
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.registerExtensionsFromPlugins$cli(KotlinCoreEnvironment.kt:659)
	... 28 more

I'm using IntelliJ iDEA 2022.01, Kotlin 1.6.20 and KSP 1.6.21-1.0.5

I checked in the source code of KSP and registerProjectComponents has the right signature.
Any idea why this issue might arise or any way to disable the plugin when the code is compiled by IntelliJ ?

Thanks in advance

@neetopia
Copy link
Collaborator

If Gradle is working but IDE is not working, it is possibly your IDE's gradle settings' issue, can you check settings in Settings/Preferences -> Build,Execution,Deployment -> Build Tools -> Gradle?

@aduchate
Copy link
Author

That's the point, I'd like to be able to compile with IntelliJ and not using gradle. If I use gradle as the build system, it works fine. When I was using kapt, the behaviour was that kapt wasn't called at all when the build was made using IntelliJ native build system. I would love to be able to have the same behaviour using kpt.

@tklinchik
Copy link

See exactly the same issue, also tried 1.7.0-Beta (in Gradle and IntelliJ plugin) and still get the same

@neetopia
Copy link
Collaborator

neetopia commented Jun 9, 2022

This might be caused by incompatible compilers used in Gradle and cmdline mode. Can you try to replace the artifact to be using symbol-processing-cmdline?

@tklinchik
Copy link

Tried with symbol-processing-cmdline artifact but IntelliJ is still not happy.

@tklinchik
Copy link

Any more color on this issue? Hard to believe KSP is getting a ton of traction in a community without InteliJ support for it

@Zaky7
Copy link

Zaky7 commented Apr 25, 2023

any update on this issue i am also getting this exception
com.google.devtools.ksp.KotlinSymbolProcessingComponentRegistrar is not compatible with this version of compiler

@tklinchik
Copy link

Doesn't seem like there is a solution for this that I'm aware of. I'm forced to use Gradle executor in IntelliJ rather than IDEA as a workaround.

@neetopia
Copy link
Collaborator

please make sure the compiler version used by KSP is matching the compiler version used by your build tool (IntelliJ Gradle executor in your case).

@tklinchik
Copy link

That's what I have currently unless IntelliJ for some reason uses different internal compiler version which seems unlikely.
I've gone through many versions of IntelliJ, gradle and kotlin and still see the same issue.
Any way I can confirm your suspicion of compiler version difference?
The error almost seems to imply classpath differences when running in IntelliJ but I can't figure out what's actually expected to be there.

@neetopia
Copy link
Collaborator

well let's take one step back, what do you mean by use Gradle executor in IntelliJ rather than IDEA?

@tklinchik
Copy link

In IntelliJ Preferences under "Build, Execution, Deployment" -> "Build Tools" -> "Gradle" there are few options under "Run tests using". If you chose "IntelliJ IDEA" then the issue will manifest, if you choose "Gradle" then the issue goes away when running tests.

@neetopia
Copy link
Collaborator

Well that's what I originally meant then. You should be choosing Gradle for running tasks if you are using Gradle as the build tools for the project. It is also mentioned in the same setting window that if you are running a Gradle project with IDEA runner, Gradle plugins might not work and you might get incorrect results.

@ianbrandt
Copy link

Perhaps this is more of an issue to be filed against IntelliJ, similar to https://youtrack.jetbrains.com/issue/KT-15040/Support-Kapt-in-IDEA-build-system-JPS.

@be-hase
Copy link

be-hase commented May 30, 2023

Also reproduced in ksp playground...
https://github.com/google/ksp/tree/main/examples/playground

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants