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


Rust And C++ Should Be Friends?
20/11/2024

The Rust Foundation has just released a statement on Rust and C++ interoperability and Google is ponying up $1000,000 to see that it gets done.



Data Wrangler Gets Copilot Integration
11/11/2024

Microsoft has announced that Copilot is being integrated into Data Wrangler. The move will give data scientists the ability to use natural language to clean and transform data, and to get help with fi [ ... ]


More News

espbook

 

Comments




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

Last Updated ( Wednesday, 27 December 2023 )