tschuchortdev / kotlin-compile-testing

A library for testing Kotlin and Java annotation processors, compiler plugins and code generation
Mozilla Public License 2.0
658 stars 63 forks source link

Fails while running tests using kotlin-compile-testing-ksp #279

Closed Alankar0416 closed 2 years ago

Alankar0416 commented 2 years ago

I am trying to run some tests using kotlin-compile-testing-ksp:1.4.2 but end up getting this error. Not able to figure out the reason.

Looks like something is missing from KSP. The version that I am using is 1.5.31-1.0.1

e: java.lang.NoSuchMethodError: 'void com.google.devtools.ksp.processing.impl.MessageCollectorBasedKSPLogger.<init>(org.jetbrains.kotlin.cli.common.messages.MessageCollector)'
        at com.tschuchort.compiletesting.KspCompileTestingComponentRegistrar.registerProjectComponents(Ksp.kt:176)
        at com.tschuchort.compiletesting.MainComponentRegistrar.registerProjectComponents(MainComponentRegistrar.kt:40)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.registerExtensionsFromPlugins$cli(KotlinCoreEnvironment.kt:610)
        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 com.tschuchort.compiletesting.AbstractKotlinCompilation.compileKotlin(AbstractKotlinCompilation.kt:184)
        at com.tschuchort.compiletesting.KotlinCompilation.compileJvmKotlin(KotlinCompilation.kt:469)
        at com.tschuchort.compiletesting.KotlinCompilation.compile(KotlinCompilation.kt:645)
        at com.uber.parameter_processor.processor.ParameterAnnotationProcessorTest.compile(ParameterAnnotationProcessorTest.kt:43)
        at com.uber.parameter_processor.processor.ParameterAnnotationProcessorTest.test1(ParameterAnnotationProcessorTest.kt:74)
        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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
        at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
        at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
        at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
        at com.facebook.buck.testrunner.SameThreadFailOnTimeout.lambda$new$0(SameThreadFailOnTimeout.java:41)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        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:829)
tschuchortdev commented 2 years ago

You always have to use the version of kotlin-compiler-embeddable and KSP that matches the KCT version. If I check out the 1.4.2 tag, it says in the readme that the matching compatible compiler version at that time was 1.5.10, so it's natural that you receive binary incompatibility errors. You should use KCT version 1.4.5 or use KSP 1.5.10.

Alankar0416 commented 2 years ago

Thanks for your reply

Alankar0416 commented 2 years ago

I tried using KCT version 1.4.5 along with kotlin-compiler-embeddable:1.5.31 and KSP:1.5.31-1.0.1 as per your suggestion. But still getting the same error.

I tried changing the dependencies as per this example. Here we are using -
KCT:1.4.4 kotlin-compiler-embeddable:1.5.31 KSP:1.5.31-1.0.0

Now the tests are working. Do you know why it should not work with 1.4.5?

Alankar0416 commented 2 years ago

It is also throwing the same error with these set of versions

KCT:1.4.4 kotlin-compiler-embeddable:1.5.31 KSP:1.5.31-1.0.1

So we can say KCT:1.4.4 is working with compiler version 1.0.0 but not with 1.0.1

tschuchortdev commented 2 years ago

That's weird. It must have worked with that version (1.5.31-1.0.0) at the time of publishing, demonstrably, or else the CI pipeline would have failed. I've checked out the repository you linked and its tests passed for me both with KCT 1.4.5, 1.4.4, 1.4.2 and surprisingly 1.4.8. KCT 1.4.5 also worked for me with KSP 1.5.31-1.0.1. Perhaps there are weird things going on with caching, but even invalidating the IDE caches doesn't change the result.

Alankar0416 commented 2 years ago

The same is true for KCT:1.4.5

Works :

KCT:1.4.5 kotlin-compiler-embeddable:1.5.31 KSP:1.5.31-1.0.0

Does not work: KCT:1.4.5 kotlin-compiler-embeddable:1.5.31 KSP:1.5.31-1.0.1

Alankar0416 commented 2 years ago

I was also suspecting caching but then I cloned the repository and added dependencies again to verify if this is due to caching. Same results

tschuchortdev commented 2 years ago

I can't personally reproduce this, so I'm just gonna trust you that the issue is with KSP 1.5.31-1.0.1 while the library was built with KSP 1.5.31-1.0.0. Unfortunately, I can't amend the documentation retroactively to point this out, but I hope that it's working for you now, at least.

Alankar0416 commented 2 years ago

Yes, @tschuchortdev we moved our stack to

KSP: 1.6.21-1.0.5 kotlin-compiler-embeddable:1.6.21 KCT: 1.4.8 KCT-KSP: 1.4.8

I have verified that it's working fine now with this stack.

Thanks for taking a look at this.