Skip to content

Commit 10e097e

Browse files
committed
Fix ksp
1 parent 89b7796 commit 10e097e

File tree

4 files changed

+25
-17
lines changed

4 files changed

+25
-17
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2222

2323
## [Unreleased]
2424
### Added
25-
- No new features!
25+
- KSP support is now stable and no longer experimental. You can now use KSP by following the instructions in the [README](README.md).
2626
### Changed
2727
- Update the project to use KTS scripts, convention plugins, version catalogs and other modern Gradle and Android features.
2828
### Deprecated

README.md

+5-6
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Then, add the following dependencies to your module's `build.gradle`:
4242

4343
```groovy
4444
dependencies {
45-
def mini_version = "3.1.0"
45+
def mini_version = "<latest_version>"
4646
// Minimum working dependencies
4747
implementation "com.github.hyperdevs-team.mini-kotlin:mini-android:$mini_version"
4848
// Use kapt as your annotation processor
@@ -68,7 +68,7 @@ dependencies {
6868

6969
```kotlin
7070
dependencies {
71-
val miniVersion = "3.1.0"
71+
val miniVersion = "<latest_version>"
7272
// Minimum working dependencies
7373
implementation("com.github.hyperdevs-team.mini-kotlin:mini-android:$miniVersion")
7474
// Use kapt as your annotation processor
@@ -90,9 +90,8 @@ dependencies {
9090

9191
</details>
9292

93-
If you want, you can also use *Kotlin Symbol Processing (KSP)* instead of KAPT. Keep in mind that
94-
support for it is **EXPERIMENTAL** and that
95-
[KSP has some gotchas that can be worked around](#ksp-gotchas), so double check before using this
93+
If you want, you can also use *Kotlin Symbol Processing (KSP)* instead of KAPT. Keep in mind that
94+
[KSP may have some gotchas that can be worked around](#ksp-gotchas), so double check before using this
9695
and report any issue that you find while working with KSP.
9796

9897
<details><summary>KSP extra dependencies</summary>
@@ -104,7 +103,7 @@ Add this to your main `build.gradle`:
104103
```groovy
105104
buildscript {
106105
ext {
107-
ksp_version = <latest_ksp_version>
106+
ksp_version = "<latest_ksp_version>"
108107
}
109108
110109
dependencies {

app/build.gradle.kts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
plugins {
22
alias(libs.plugins.android.application)
33
alias(libs.plugins.kotlin.android)
4-
alias(libs.plugins.kotlin.kapt)
4+
// alias(libs.plugins.kotlin.kapt)
55
alias(libs.plugins.kotlin.ksp)
66
alias(libs.plugins.convention.androidApp)
77
}
@@ -59,8 +59,8 @@ dependencies {
5959
implementation(project(":mini-android"))
6060
implementation(project(":mini-kodein-android"))
6161

62-
kapt(project(":mini-processor"))
63-
//ksp(project(":mini-processor"))
62+
// kapt(project(":mini-processor"))
63+
ksp(project(":mini-processor"))
6464

6565
// Kotlin
6666
implementation(libs.kotlin.stdlib)

mini-processor/src/main/java/mini/processor/ksp/MiniSymbolProcessor.kt

+16-7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.google.devtools.ksp.processing.CodeGenerator
44
import com.google.devtools.ksp.processing.Resolver
55
import com.google.devtools.ksp.processing.SymbolProcessor
66
import com.google.devtools.ksp.symbol.KSAnnotated
7+
import com.google.devtools.ksp.symbol.KSClassDeclaration
78
import com.squareup.kotlinpoet.ksp.writeTo
89
import mini.Action
910
import mini.Reducer
@@ -23,17 +24,21 @@ class MiniSymbolProcessor(
2324
val actionSymbols = resolver.getSymbolsWithAnnotation(Action::class.java.canonicalName)
2425
val reducerSymbols = resolver.getSymbolsWithAnnotation(Reducer::class.java.canonicalName)
2526

27+
// Collect the files that contain the symbols, we will use this to set the originating files
28+
// for the generated code and incremental processing.
29+
val originatingKsFiles = (actionSymbols + reducerSymbols).
30+
filterIsInstance<KSClassDeclaration>()
31+
.mapNotNull { it.containingFile }
32+
.distinct()
33+
.toList()
34+
2635
if (!actionSymbols.iterator().hasNext()) return emptyList()
2736

2837
val (containerFile, container) = getContainerBuilders()
2938

3039
try {
31-
ActionTypesGenerator(KspActionTypesGeneratorDelegate(actionSymbols)).generate(
32-
container
33-
)
34-
ReducersGenerator(KspReducersGeneratorDelegate(reducerSymbols)).generate(
35-
container
36-
)
40+
ActionTypesGenerator(KspActionTypesGeneratorDelegate(actionSymbols)).generate(container)
41+
ReducersGenerator(KspReducersGeneratorDelegate(reducerSymbols)).generate(container)
3742
} catch (e: Throwable) {
3843
if (e !is ProcessorException) {
3944
kspLogError(
@@ -46,7 +51,11 @@ class MiniSymbolProcessor(
4651
containerFile
4752
.addType(container.build())
4853
.build()
49-
.writeTo(codeGenerator, true)
54+
.writeTo(
55+
codeGenerator = codeGenerator,
56+
aggregating = true,
57+
originatingKSFiles = originatingKsFiles
58+
)
5059

5160
return emptyList()
5261
}

0 commit comments

Comments
 (0)