KSP2 is a new implementation of the KSP API. Unlike KSP 1.x, it is no longer a compiler plugin and is built on the same set of Kotlin compiler APIs shared with IntelliJ IDEA, Android Lint, etc. Compared to the compiler-plugin approach, this allows a finer control of the program life cycle, simplifies KSP’s implementation and is more efficient. It is also a response to the compiler migration to K2, whose compiler plugin API is different from the one KSP1 uses.
Not being a compiler plugin and having a better control of the program life cycles means that it’s straightforward to provide an entry point that can be called by other programs. This is especially convenient for testing processors as a processor author. KSP2 also provides a new command line tool that has its own main function, instead of being part of the compiler invocation.
With the new implementation, it is also a great opportunity to introduce some refinements in the API behavior so that developers building on KSP will be more productive, have better debuggability and error recovery. For example, when resolving Map<String, NonExistentType>, KSP1 simply returns an error type. In KSP2, Map<String, ErrorType> will be returned instead.
Please refer to KSP2 API Changes to see more details.
Unlike KSP1, which runs in KotlinCompileDaemon, KSP2 runs in Gradle daemon. This has 2 implications:
org.gradle.jvmargs=-Xmx4096M -XX:MaxMetaspaceSize=1024mKotlinCompileDaemon. To debug KSP2 and/or processors, pass the system property -Dorg.gradle.debug=true in the Gradle command line.Please refer to Using KSP2 command line and Calling KSP2 in program.
The main gaps between KSP2 Beta and KSP2 Stable are:
inline and internal) JVM names in Resolver.getJvmWildcard and Resolver.mapToJvmSignatureResolver.findOverridee and Resolver.asMemberOf.Please check the KSP 2.0 and 2.1 milestones on GitHub for the complete lists of known issues.
If you find any bugs that are not included in the above milestones, or if you have any concerns or ideas on API changes, please let us know!