rules_kotlin icon indicating copy to clipboard operation
rules_kotlin copied to clipboard

Support KSP annotation processing

Open Bencodes opened this issue 4 years ago • 8 comments

First pass at supporting KSP annotation processing as an alternative to Kapt.

This PR runs KSP as part of the existing KotlinCompile action so that Kotlinc only has to be invoked once while compiling a target. We could optionally pull this out into a unique action, like we do for Kapt, at the cost of re-processing Kotlin sources.

Bencodes avatar Feb 05 '22 20:02 Bencodes

I've been planning on moving my Kotlin Gradle project to Bazel lately, but Bazel's support for Kotlin ecology seems imperfect, so I'm just curious if KSP can't be implemented like Jetpack Compose? Just apply the Kotlin compiler plugin, because essentially, KSP is just a KCP plugin

chachako avatar Feb 08 '22 06:02 chachako

I've been planning on moving my Kotlin Gradle project to Bazel lately, but Bazel's support for Kotlin ecology seems imperfect, so I'm just curious if KSP can't be implemented like Jetpack Compose? Just apply the Kotlin compiler plugin, because essentially, KSP is just a KCP plugin

@RinOrz it should theoretically be possible. I took this approach because I was interested in at a lower level so that we could play around with performance a bit more (Ex: Running KSP in a standalone action like we do for kapt vs running as part of the existing Kotlin compile).

Bencodes avatar Feb 16 '22 16:02 Bencodes

What's the status of this? Is there any way I could help?

Kernald avatar Jul 27 '22 23:07 Kernald

What's the status of this? Is there any way I could help?

Definitely needs some more testing. We are moving over our annotation processors over the KSP internally and will hopefully have something to report back with in the coming weeks.

My hope here is that we don't actually need to build this into rules_kotlin and that we can just lean into the existing Kotlinc plugin infrastructure that exists.

Bencodes avatar Jul 28 '22 16:07 Bencodes

@Bencodes have you considered whether KSP can be used in a target that also runs KAPT, and if so, if KSP & KAPT can depend on each other's outputs? Looking at https://github.com/google/ksp/issues/863 that decision hasn't been made yet in Gradle-land.

lukaciko avatar Aug 09 '22 14:08 lukaciko

@lukaciko that's not a case that we've accounted for and not sure if we do. This seems like something that would add a lot of complexity to our annotation processing, and even introduce some clashing between the two.

Bencodes avatar Aug 15 '22 19:08 Bencodes

@Bencodes I think it's fair enough if it is not supported, as long as that's clear and explicit. I'd like to avoid one of those cases where something is accidentally supported in one version of the rules and gets dropped in another.

lukaciko avatar Aug 22 '22 08:08 lukaciko

I took another stab at getting a less intrusive version of KSP working yesterday. This approach does work and it comes with the added benefit of us not needing to couple KSP to rules_kotlin.

https://github.com/bazelbuild/rules_kotlin/pull/829

Bencodes avatar Aug 24 '22 16:08 Bencodes