Skip to content

Commit 61bb46b

Browse files
authored
Support KSP2 (#4)
* Small change to make Enum interpretation compatible with the KSP2 runtime * Add integration tests for KSP2 * Make KSP dependencies compileOnly
1 parent bfeb7f6 commit 61bb46b

File tree

20 files changed

+269
-11
lines changed

20 files changed

+269
-11
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
plugins {
22
`kotlin-conventions`
33
`publishing-conventions`
4-
alias(libs.plugins.ksp)
4+
alias(libs.plugins.ksp1)
55
}
66

77
dependencies {
88
ksp(libs.autoservice.ksp)
9-
implementation(libs.ksp.api)
10-
implementation(libs.autoservice.annotations)
9+
compileOnly(libs.ksp.api)
10+
compileOnly(libs.autoservice.annotations)
1111
implementation(libs.kotlinPoet)
1212
implementation(libs.kotlinPoetKsp)
1313
}

eventbus-index-ksp-processor/src/main/kotlin/com/toasttab/eventbus/ksp/Parser.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,14 @@ private fun parseSubscribeAnnotation(annotation: KSAnnotation): MaybeSubscribeAn
3030

3131
val threadMode = args["threadMode"]
3232

33-
if (threadMode !is KSType) {
34-
return InvalidSubscribeAnnotation("@Subscribe.threadMode = $threadMode is not an enum value")
33+
val threadModelEnumValue = if (threadMode is KSType) {
34+
// KSP1
35+
threadMode.toClassName()
36+
} else if (threadMode is KSClassDeclaration) {
37+
// KSP2
38+
threadMode.toClassName()
39+
} else {
40+
return InvalidSubscribeAnnotation("@Subscribe.threadMode = $threadMode is not a valid enum value")
3541
}
3642

3743
val sticky = args["sticky"]
@@ -46,7 +52,7 @@ private fun parseSubscribeAnnotation(annotation: KSAnnotation): MaybeSubscribeAn
4652
return InvalidSubscribeAnnotation("@Subscribe.priority = $priority is not an Int value")
4753
}
4854

49-
return SubscribeAnnotation(threadMode.toClassName(), sticky, priority)
55+
return SubscribeAnnotation(threadModelEnumValue, sticky, priority)
5056
}
5157

5258
private fun KSAnnotated.subscriberAnnotation() = annotations.find {

gradle/libs.versions.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ kotlinPoet = "2.1.0"
1010

1111
eventbus = "3.3.1"
1212

13-
ksp = "2.1.20-1.0.32"
13+
ksp1 = "2.1.20-1.0.32"
14+
ksp2 = "2.1.20-2.0.0"
1415
autoservice-ksp = "1.2.0"
1516

1617
# test
@@ -26,7 +27,7 @@ autoservice = { module = "com.google.auto.service:auto-service", version.ref = "
2627
kotlinPoet = { module = "com.squareup:kotlinpoet", version.ref = "kotlinPoet" }
2728
kotlinPoetKsp = { module = "com.squareup:kotlinpoet-ksp", version.ref = "kotlinPoet" }
2829

29-
ksp-api = { module = "com.google.devtools.ksp:symbol-processing-api", version.ref = "ksp" }
30+
ksp-api = { module = "com.google.devtools.ksp:symbol-processing-api", version.ref = "ksp1" }
3031

3132
# ksp
3233
autoservice-ksp = { module = "dev.zacsweers.autoservice:auto-service-ksp", version.ref = "autoservice-ksp"}
@@ -42,4 +43,5 @@ junit-launcher = { module = "org.junit.platform:junit-platform-launcher"}
4243
strikt-core = { module = "io.strikt:strikt-core", version.ref = "strikt" }
4344

4445
[plugins]
45-
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp"}
46+
ksp1 = { id = "com.google.devtools.ksp", version.ref = "ksp1"}
47+
ksp2 = { id = "com.google.devtools.ksp", version.ref = "ksp2"}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (c) 2025 Toast Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
plugins {
17+
`kotlin-conventions`
18+
}
19+
20+
dependencies {
21+
implementation(libs.eventbus)
22+
}
File renamed without changes.

integration-tests/build.gradle.kts renamed to integration-tests/ksp1/build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
plugins {
1717
`kotlin-conventions`
18-
alias(libs.plugins.ksp)
18+
alias(libs.plugins.ksp1)
1919
}
2020

2121
ksp {
@@ -24,5 +24,6 @@ ksp {
2424

2525
dependencies {
2626
ksp(project(":eventbus-index-ksp-processor"))
27+
implementation(project(":integration-tests:common"))
2728
implementation(libs.eventbus)
2829
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)