-
Notifications
You must be signed in to change notification settings - Fork 14
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
Support Kotlin 2.0 #77
Comments
Thanks for the detailed explanation of the problem. Even if I am pretty sure that I am only beginning to understand the basic setup maybe we can exchange a few thoughts here. If I understand the KSP docs here correctly there seems to be a kspTest task for multiplatform. Could we maybe hook into that? Also: Did you already investigate whether KSP 2.0 might or might not have an impact or helpful changes for the issue? I am struggling with finding specific information about it. |
There's no kspCommonMainMetadata As I've explained applying KSP to each test sourceset does not work because of K2 Common / Target sourceset separation. |
Thanks for the explanation! So it looks like the issue here is really just that KSP runs for anything except commonTest if I see it well. Does this mean we could generate files for jvm test for example and run the tests there? I know it is not the goal of a multiplatform library to limit tests to the different sub packages, I am just trying to understand the underlying issue. In the meantime I will add my vote to the KSP issue and ask the ksp team to shed a light on why they seem to exclude commonTest explicitly. Edit: would it be possible to move the generated code from one folder to the other in the generation step? I know this is hacky but it might keep the project running until the underlying issues in KSP are resolved/KSP is extended |
Hello, i get the same issue, i choose to stay on ksp 1.9.24-1.0.20 for now instead removing MocKMP usage. |
Any solutions please , we are blocked due to this issue since we would like to migrate to kotlin 2.0 |
Hi guys. |
Good news : I found a way to make MocKMP work with Kotlin 2 ! I should add that this new mechanism does NOT use weird sourceset tricks, so it should be much more future-proof than the current version 😄 |
Here we are: MocKMP 2.0 has been released to Maven Central and to the Gradle plugin portal. Migration guideI truly apologize for the time it took me to port MocKMP to Kotlin 2.0. All I can say for my defense is that:
The way MocKMP 2.0 is implemented is now much more robust and future-ready than version 1.x (at least, I think so, but I do not live in the future). I am quite satisfied at where the project is and I hope it will be less of a hassle to maintain for the coming Kotlin releases. |
This issue is here to discuss the path to supporting K2. It outlines the issues I've encountered as well as their possible workarounds. Feel free to enter the discussion, especially if you have any insight or wild idea ;)
MocKMP generates source code for the Test source-sets, which is not properly supported by KSP. KSP does support generating code for the
commonMain
sourceset, but not for thecommonTest
sourceset.Up until now, we've used the following trick: register the MocKMP processor only in the
kspJvmTest
configuration and have thecommonTest
sourceset use thebuild/generated/ksp/jvm/jvmTest/kotlin
directory. This requires some more Gradle configuration (namely having all targets compilation task to depend onkspTestKotlinJvm
) but it worked allright (even though it made my heart ache).Kotlin 2.0 brings a new issue:
It looks like K2 is more restrictive than K1, and does not allow the same file to be in multiple sourcesets at once. I also haven't found a way to emulate running KSP to
commonTest
only, or to remove thegenerated/ksp/jvm/jvmTest/kotlin
directory from the JVM test compilation.I've tried another approach that consists of applying the processor to all test targets:
...but that brings a new issue: because K2 is also more restrictive as to which sources are accessed when compiling common code, this approach does not compile at all (yielding unresolved symbol all around errors when compiling common code).
So far, the only approach I've thought of that would (I think) resolve the issue is to follow the KotlinX.RPC & KotlinX.Serialization paths and have a Compiler plugin that adds an
AssociatedObjectKey
annotation to each class annotated with@Mock
or@Fake
. This cannot be done with KSP as it notoriously cannot modify the sources of the code it is processing. Such annotations allow a Native & Js code to access an object associated to a class at compile-time (it does not exist in JVM, but the JVM provides reflection so there's no need for it). This in turn allows to have a common code that does not directly reference generated code.This is a path I'd rather not take, because:
MocKMP is now at a crossroad as I have found, at the moment, no satisfactory path to have it compatible with K2.
Let's keep looking!
Make sure to share any idea or knowledge I've missed ;)
The text was updated successfully, but these errors were encountered: