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
russhwolf
05/03/2021, 4:27 PM
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.
russhwolf
05/03/2021, 4:27 PM
maybe you could hack something together with dummy classes on the JVM side since you don't actually need it to run
n
natario1
05/03/2021, 4:47 PM
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
russhwolf
05/03/2021, 4:59 PM
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