Is it possible to use KSP on non-JVM source sets i...
# ksp
n
Is it possible to use KSP on non-JVM source sets in a multiplatform project, even if compilation will fail? Say you have a non-JVM target and you are interested in analyzing the source code, without code generation. For example, count how many functions have the
@Function
annotation. May be a weird idea but what I'm thinking is: • add a fake JVM target which reads the non-JVM source set • run KSP on this target, count
@Function
s or any other read-only symbol operation • have compilation fail, we don't care because it's a fake target Would this be possible? I'm not sure if KSP gets a chance to run if the source set is not compilable (it has non-JVM imports, non-JVM dependencies...)
r
I did a proof-of-concept sort of like this with common code, where I had a jvm module that applies KSP and a multiplatform module that includes the same source in its common source-set. I wouldn't be optimistic that it would work if you needed to include platform-specific code on non-JVM platforms.
maybe you could hack something together with dummy classes on the JVM side since you don't actually need it to run
n
I tried with a simple setup, having a JVM source set, but adding unresolved imports, say
import foo
and later
foo.bar()
. My KSP processor just logs hello world. Great news is that in a clean gradle build, I can see the KSP log before failure. If this works with other platforms too (it should?), I think we only need a way to catch and swallow the error. In Gradle or maybe some special compiler flag
r
Issue I ran into is, if you have other platforms besides JVM then including KSP will fail the build. That's why I set up a separate JVM-only project just to do the KSP analysis
It's not pretty
n
You're right... Got stuck against https://github.com/google/ksp/issues/367
r
Right, that's why I could only get it working by running ksp from a separate jvm module