KSP2 Adds Kotlin K2 Support
Written by Mike James   
Wednesday, 27 December 2023

Google has announced the preview version of KSP2, the next version of the Kotlin Symbol Processing tool which is a good way to meta program.

KSP provides a high-level API for doing meta-programming in Kotlin, and can be used to develop lightweight compiler plugins. KSP provides a simplified compiler plugin API that makes use of the power of Kotlin while keeping the learning curve at a minimum. Compared to KAPT (Kotlin Annotation Processing Tool), annotation processors that use KSP can run up to two times faster.

kotlinlogo

Kotlin is the open source language originated by JetBrains and promoted by Google as a first class language for Android to replace or supplement Java. It makes Android programming easier by reducing the need for long chunks of boilerplate code.

Alongside a new architecture designed to fill in gaps in the previous version, KSP2 has preview support for the new Kotlin compiler (code-named K2), along with a new standalone source generator that provides more flexibility and features than the current Kotlin compiler plugin.

Internally KSP2 uses the beta Kotlin K2 compiler (which will be the default compiler in Kotlin 2.0). The previous version of KSP was implemented as a Kotlin compiler plugin, meaning you need to run the compiler and specify KSP and its plugin options in order to run it. This made debugging and testing more difficult, particularly in Gradle.

The KSP developers say that in KSP2, the implementation can be thought of as a library with a main entry point so can be called without setting up the compiler, making it easy to call KSP programmatically and for debugging and testing.

The team has also used the implementation as an 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.

There's also a new multiplatform processing scheme that avoids the need for common or shared source sets to be processed and compiled multiple times, with each target. KSP2 has an experimental mode that tries to align to how source sets are compiled in K2 better, meaning that all sources can be processed only once. 

KSP2 is available in preview now, and the new preview changes can be enabled in KSP 1.0.14 or newer using a flag in gradle.properties, ksp.useKSP2=true.

kotlinlogo

More Information

Kotlin Home Page

KSP On GitHub

Related Articles

Kotlin 1.9 Adds K2 Compiler

Kotlin 1.8 Beta Adds New JVM Functions

Kotlin 1.7 Unveils New Compiler

Kotlin 1.5 - Mature But Still Growing

Why Do Android Devs Convert To Kotlin?

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

Banner


GitLab Releases Duo Chat
22/04/2024

GitLab has announced that Duo Chat is now generally available in GitLab 16.11, offering a range of AI features in a single natural language chat experience.



Grow with Google Launches Generative AI Course
26/04/2024

Grow with Google, in collaboration with MIT RAISE (Responsible AI for Social Empowerment and Education), is launching a no-cost Generative AI for Educators course.


More News

raspberry pi books

 

Comments




or email your comment to: comments@i-programmer.info

Last Updated ( Wednesday, 27 December 2023 )