picocli icon indicating copy to clipboard operation
picocli copied to clipboard

KSP support for Kotlin?

Open martinbonnin opened this issue 3 years ago • 5 comments

The current Kotlin integration requires kapt which is working well but has issues and is in maintenance mode (see https://youtrack.jetbrains.com/issue/KT-48661).

Are there any plans to move to KSP ?

martinbonnin avatar Feb 06 '22 12:02 martinbonnin

Hi @martinbonnin thanks for raising this. I was not aware of KSP.

For kapt, there is not much that picocli actively does, people can just configure picocli's java-based annotation processor in picocli-codegen and it just works. So from my point of view I just needed to document how people could use kapt with picocli.

As far as I can tell after a very brief glance, KSP unfortunately is a completely parallel API to the java annotation processing API and is not compatible. So that would mean developing and maintaining a KSP version of the picocli-codegen module. Given how little time I have for picocli recently, that is not an attractive proposition... Still thinking about this.

remkop avatar Feb 06 '22 21:02 remkop

Thanks for the quick reply!

As you found out, the KSP API is completely different so it might require some work indeed. The main difference is that kapt generates Java stubs to run the java codegen on it so it adds to the build time by adding this intermediate step.

It also has limitations. One that comes to mind is interfaces nested in interfaces with the same name. This is legal in Kotlin but not in Java (Youtrack issue) but I'm pretty sure there are others.

I unfortunately don't have much time to work on this either but was curious if this was ever considered. I'll keep watching this issue in case this gets some traction one day :)

martinbonnin avatar Feb 06 '22 21:02 martinbonnin

I am going to close this for now. I don't see myself working on this, and I am not sure that I would accept a contribution that implements the equivalent of the current picocli-codegen annotation processor using the KSP API... I may change my opinion if annotation processors completely stop working for Kotlin.

remkop avatar Feb 12 '22 09:02 remkop

I think in the future kapt may not be feasible: https://kotlinlang.org/docs/kapt.html

they're keeping it only in maintenance mode now, an all new functionality is going into ksp.

dkowis avatar Dec 20 '23 22:12 dkowis

I think in the future kapt may not be feasible: https://kotlinlang.org/docs/kapt.html

they're keeping it only in maintenance mode now, an all new functionality is going into ksp.

@dkowis Understood, so that has not really changed.

I would be more open to a KSP contribution from contributors: again, I will not be able to work on this myself, so if it breaks or if any bugs are found, I would have to rely on the contributors or wider community to help fix/improve such issues.

I will reopen this ticket.

remkop avatar Dec 21 '23 00:12 remkop