- Kotlin code generation (Kotlin CodeGen) is available in Room KSP, enabled by adding the room.generateKotlin option to the KSP processor options
- A new Room Gradle Plugin artifact with the id androidx.room is available, resolving issues with schema inputs and outputs via Gradle annotation processor options
- Value classes in Room Entities are supported for KSP
- Nested Map return types in DAO functions are supported
- Abstract properties used as DAO getters or DAO queries are disallowed with Kotlin CodeGen and must be rewritten as functions
- Nullability of type arguments is enforced with Kotlin CodeGen, so projects may report errors where Java CodeGen ignored them, such as a Flow return type emitting null for an empty table
- Nullable collection return types are no longer allowed in Room when using Kotlin CodeGen
From Room
The option to enable Kotlin code generation (or Kotlin CodeGen) is now available in Room KSP. ( 4297ec0). To turn on Kotlin CodeGen in Room, add the room.generateKotlin option name to your processor options for KSP. For more details on how to pass processor options for KSP, see the KSP documentation. Note: When using Kotlin CodeGen, it is important to note that there are additional restrictions that have been added. Abstract properties as DAO getters or DAO queries in Kotlin CodeGen are disallowed, and instead expected to be rewritten as functions to avoid the false notion that the property value is immutable and has a fixed stored result. Another restriction that has been added is that Nullable collection return types are no longer allowed in Room for Kotlin CodeGen. Warning: You may find that your projects are more strict in terms of nullability when using Kotlin CodeGen. In Kotlin CodeGen, the nullability of type arguments is important, wheras in Java this is mostly ignored. For example, let's say you have a Flow return type and the table is empty. In Java CodeGen, this will not cause any issues, but in Kotlin CodeGen, you will get an error. To avoid this, you will need to use Flow, assuming a null is emitted. The new artifact for the Room Gradle Plugin has been added to Room with the id androidx.room, which solves various existing issues in Room regarding having inputs and outputs of schemas via Gradle annotation processor options. For more details, refer to the Room Version 2.6.0-alpha02 release notes. Value classes in Room Entities are now supported for KSP. ( 4194095) Nested Map return types in DAO functions are now supported in Room. ( I13f48, 203008711)