I have a class with an annotation picked up by KSP...
# ksp
j
I have a class with an annotation picked up by KSP under a package
com.my.package
. The generated code is under the package
<http://com.my|com.my>.package.<class name>
. While running my tests with js target (multiplatform project) I get no error and the tests pass. But when running the test with jvm target, they all fail with
Unresolved reference: <my generated code>
. If I generate all the code under
com.my.package
then I don’t have any issues at all with jvm target. Am I suppose to add the custom package names to the source sets?
g
(since 24h has already passed, some random question from a noob in the hope it may help) 1- is the error coming from a generated class that references a generated class or from a class that references a generated class? 2- if it was the second choice, are you importing the generated class in your kotlin class? (I mean the usual
import
at the beginning of the file) (I believe it's not required to update sourceSets with generated code anymore with latest KSP version, not tested tho, but you can easily try it)
j
The error comes when I run my unit tests targeting the jvm. The test can't find the generated class. I can command click on the import and it's resolved, the error only occurs specifically when running the test
g
Have you tried something like this?
Copy code
kotlin {
    sourceSets["jvmTest"].kotlin.srcDir("build/generated/ksp/metadata/commonMain/kotlin")
}
j
Weirdly enough, when I had this my IDE can’t resolve the generated classes anymore
Well, turned out that updating kotlin and ksp to 1.8.21 fixed the issue 🤷🏻