Skip to content

Commit 389dfcb

Browse files
authored
feat: update Kotlin version and dependencies, enhance NavParam annotation, and improve KSP test utilities (#458)
1 parent d24aee2 commit 389dfcb

File tree

9 files changed

+37
-23
lines changed

9 files changed

+37
-23
lines changed

.idea/kotlinc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.java-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
21.0.8

annotation/build.gradle.kts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
plugins {
22
id("co.anitrend.arch")
3+
kotlin("jvm")
4+
}
5+
6+
kotlin {
7+
sourceSets {
8+
main {
9+
kotlin.srcDirs("src/main/kotlin")
10+
}
11+
}
312
}

annotation/src/main/kotlin/co/anitrend/arch/annotation/NavParam.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ package co.anitrend.arch.annotation
2424
* @since 1.8.0
2525
*/
2626
@Target(AnnotationTarget.CLASS)
27-
@Retention(AnnotationRetention.SOURCE)
27+
@Retention(AnnotationRetention.BINARY)
2828
annotation class NavParam(
2929
val enabled: Boolean = true,
3030
)

extension/src/androidTest/kotlin/co/anitrend/arch/extension/util/AbstractSupportDateHelperTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ import co.anitrend.arch.extension.util.date.contract.AbstractSupportDateHelper
2323
import com.jakewharton.threetenabp.AndroidThreeTen
2424
import java.util.Locale
2525
import java.util.TimeZone
26-
import org.junit.jupiter.api.Assertions.assertEquals
27-
import org.junit.jupiter.api.BeforeEach
28-
import kotlin.test.Test
26+
import org.junit.Before
27+
import org.junit.Test
28+
import org.junit.Assert.assertEquals
2929
import org.junit.runner.RunWith
3030
import org.threeten.bp.format.DateTimeFormatter
3131

@@ -44,7 +44,7 @@ class AbstractSupportDateHelperTest {
4444
InstrumentationRegistry.getInstrumentation().context
4545
}
4646

47-
@BeforeEach
47+
@Before
4848
fun setUp() {
4949
AndroidThreeTen.init(context)
5050
}

gradle/libs.versions.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jetbrains-kotlinx-coroutines = "1.10.2"
1818

1919
io-mockk = "1.14.2"
2020

21-
google-devtools-ksp = "2.1.20-1.0.32"
21+
google-devtools-ksp = "2.0.21-1.0.27"
2222

2323
[plugins]
2424
google-devtools-ksp = { id = "com.google.devtools.ksp", version.ref = "google-devtools-ksp" }
@@ -89,4 +89,4 @@ pintrest-ktlint = { module = "com.pinterest:ktlint", version.ref = "ktlint" }
8989

9090
squareup-kotlinpoet = { module = "com.squareup:kotlinpoet", version = "2.0.0" }
9191
google-devtools-ksp-api = { module = "com.google.devtools.ksp:symbol-processing-api", version.ref = "google-devtools-ksp" }
92-
kotlin-compile-testing-ksp = { module = "com.github.tschuchortdev:kotlin-compile-testing-ksp", version = "1.6.0" }
92+
kotlin-compile-testing-ksp = { module = "dev.zacsweers.kctfork:ksp", version = "0.6.0" }

processor/build.gradle.kts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,14 @@ plugins {
44
}
55

66
dependencies {
7-
implementation(project(":annotation"))
7+
api(project(":annotation"))
88
implementation(libs.squareup.kotlinpoet)
99
implementation(libs.google.devtools.ksp.api)
1010

1111
testImplementation(libs.jetbrains.kotlin.test)
1212
testImplementation(libs.kotlin.compile.testing.ksp)
1313
}
1414

15-
tasks.withType(Test::class.java) {
16-
dependsOn(":annotation:classesJar")
17-
}
18-
1915
tasks.test {
2016
useJUnitPlatform()
2117
}

processor/src/main/kotlin/co/anitrend/arch/processor/codegen/NavParamCodeGenerator.kt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ class NavParamCodeGenerator(
6969
) {
7070
val fileSpec = generateContent(classes = classes, spec = spec)
7171

72+
logger.logging("[NavParamCodeGenerator] Generating file: ${spec.packageName}.${spec.fileName}.kt for ${classes.size} classes")
73+
7274
val file =
7375
codeGenerator.createNewFile(
7476
dependencies =
@@ -92,12 +94,17 @@ class NavParamCodeGenerator(
9294
}
9395

9496
override operator fun invoke(classes: List<KSClassDeclaration>) {
95-
val packageName = classes.first().packageName.asString()
97+
val classDeclaration = classes.first()
98+
val packageName = classDeclaration.packageName.asString()
9699
val parentClassName =
97-
classes.first().parentDeclaration?.simpleName?.asString()
98-
?: throw UnsupportedOperationException(
99-
"The annotated item in `$packageName` should belong in a parent class",
100-
)
100+
classDeclaration.parentDeclaration?.simpleName?.asString()
101+
?: run {
102+
logger.error(
103+
"The annotated item in `$packageName` should belong in a parent class",
104+
classDeclaration,
105+
)
106+
return
107+
}
101108

102109
val spec =
103110
Spec(

processor/src/test/kotlin/co/anitrend/arch/processor/utils/KspTestUtil.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package co.anitrend.arch.processor.utils
22

33
import com.google.devtools.ksp.processing.SymbolProcessorProvider
4+
import com.tschuchort.compiletesting.JvmCompilationResult
45
import com.tschuchort.compiletesting.KotlinCompilation
56
import com.tschuchort.compiletesting.SourceFile
6-
import com.tschuchort.compiletesting.kspWithCompilation
77
import com.tschuchort.compiletesting.symbolProcessorProviders
8+
import com.tschuchort.compiletesting.useKsp2
89
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
910
import java.io.File
1011

@@ -14,17 +15,17 @@ object KspTestUtil {
1415
fun compile(
1516
sourceFiles: List<SourceFile>,
1617
symbolProcessorProviders: List<SymbolProcessorProvider>,
17-
): KotlinCompilation.Result {
18+
): JvmCompilationResult {
1819
return KotlinCompilation().also { compiler ->
1920
compiler.sources = sourceFiles
2021
compiler.inheritClassPath = true
21-
compiler.symbolProcessorProviders = symbolProcessorProviders
22+
compiler.useKsp2()
23+
compiler.symbolProcessorProviders += symbolProcessorProviders
2224
compiler.messageOutputStream = System.out
23-
compiler.kspWithCompilation = true
2425
}.compile()
2526
}
2627

27-
fun getSourcesFromResult(result: KotlinCompilation.Result): List<File> {
28+
fun getSourcesFromResult(result: JvmCompilationResult): List<File> {
2829
val kspSourcesDir = result.outputDirectory.resolve("../ksp/sources")
2930
return kspSourcesDir.walkTopDown()
3031
.filter { it.isFile && it.extension == "kt" }

0 commit comments

Comments
 (0)