Is there any differences between kapt, ir plugin, ...
# announcements
a
Is there any differences between kapt, ir plugin, and ksp (kotlin symbol processing)? 🤔
👍 1
t
I’m not the best person to answer as I only have a surface understanding of the former two but they do target different audiences. kapt: a JVM-based annotation processor. The selling point is that existing Java annotation processors will work with kapt. KSP: A purely Kotlin-focused meta-library. Though annotation processing is a pretty big selling point (namely the performance increase over kapt), KSP has a much larger feature set. It is essentially a language meta-library, it parses a kotlin program into its component pieces and allows a developer to write a tool that can analyze the program (classes, properties, functions, types, expressions, etc). It’s essentially a middle-ground between a lightweight annotation processor and heavyweight compiler plugin. Its tooling allows it to run before compilation, which means the source that produces generated code can also reference the generated code. Another nice feature of it being kotlin-focused is that it will (eventually) support multi-platform projects. The alpha tooling doesn’t yet but it is planned. I’m not quite sure what an IR plugin entails, but it seems like it is a specific way to write a compiler-level plugin working against the low-level kotlin compiler APIs.
👍 1
I will say that KSP is a fantastic tool - it’s been very helpful in my current project (the part currently using KSP is a typesafe model definition library/kotlin DSL that is consumed by a language workbench inspired by MPS and Xtext)
z
I believe kapt is basically a port of the Java annotation processor that knows about kotlin source. It’s slow, because it runs outside the compiler as a separate process that reads source code and usually outputs source code that then needs to be compiled itself. KSP is a compiler plugin that processes IR code directly. It is designed to serve similar use cases as kapt, but because it’s a compiler plugin and not a separate process, it is much lower overhead to run and can integrate more tightly with kotlin features. The kotlin compiler has always supported plugins, but until recently the api was a bit limited, and plugins had to be written specifically for one of the backends: jvm, js, or native. The new IR backend introduces a special bytecode, Intermediate Representation, that compiler plugins can read and write, that is independent of jvm/js/native. The compiler plugin api is also much more flexible and powerful. IR plugins can be written once and automatically support all of jvm, js, native, and any future targets.
👍 1