From 96a1223a313ff106ba53c22c84f965c4616a43a9 Mon Sep 17 00:00:00 2001 From: Guillermo Mazzola Date: Tue, 26 Nov 2024 22:47:46 +0100 Subject: [PATCH] Fixes issues with KSP and generated code --- demo-project/kmp/build.gradle.kts | 3 +++ .../kotlin/com/example/kmp/MoshiObjAndroid.kt | 9 +++++++++ .../src/jvmMain/kotlin/com/example/kmp/MoshiObjJVM.kt | 9 +++++++++ gradle/libs.versions.toml | 4 ++++ .../aggregation/AndroidTestCoverageAggregationPlugin.kt | 2 +- 5 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 demo-project/kmp/src/androidMain/kotlin/com/example/kmp/MoshiObjAndroid.kt create mode 100644 demo-project/kmp/src/jvmMain/kotlin/com/example/kmp/MoshiObjJVM.kt diff --git a/demo-project/kmp/build.gradle.kts b/demo-project/kmp/build.gradle.kts index 24671c8..cd7e544 100644 --- a/demo-project/kmp/build.gradle.kts +++ b/demo-project/kmp/build.gradle.kts @@ -5,6 +5,7 @@ import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension plugins { alias(libs.plugins.android.lib) alias(libs.plugins.kotlin.multiplatform) + alias(libs.plugins.kotlin.ksp) } afterEvaluate { @@ -30,5 +31,7 @@ kotlin { } dependencies { + ksp(libs.moshi.codegen) + commonMainImplementation(libs.moshi.kotlin) commonTestImplementation(libs.kotlin.test) } diff --git a/demo-project/kmp/src/androidMain/kotlin/com/example/kmp/MoshiObjAndroid.kt b/demo-project/kmp/src/androidMain/kotlin/com/example/kmp/MoshiObjAndroid.kt new file mode 100644 index 0000000..3fb610b --- /dev/null +++ b/demo-project/kmp/src/androidMain/kotlin/com/example/kmp/MoshiObjAndroid.kt @@ -0,0 +1,9 @@ +package com.example.kmp + +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +data class MoshiObjAndroid( + val a: String, + val b: String, +) diff --git a/demo-project/kmp/src/jvmMain/kotlin/com/example/kmp/MoshiObjJVM.kt b/demo-project/kmp/src/jvmMain/kotlin/com/example/kmp/MoshiObjJVM.kt new file mode 100644 index 0000000..2d47571 --- /dev/null +++ b/demo-project/kmp/src/jvmMain/kotlin/com/example/kmp/MoshiObjJVM.kt @@ -0,0 +1,9 @@ +package com.example.kmp + +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +data class MoshiObjJVM( + val a: String, + val b: String, +) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 4e03350..db42add 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -5,6 +5,7 @@ android-minSDK = "21" android-compileSDK = "35" androidx-lifecycle = "2.8.7" androidx-navigation = "2.8.4" +moshi = "1.15.1" [libraries] androidx-core = "androidx.core:core-ktx:1.15.0" @@ -19,6 +20,8 @@ androidx-test-junit = "androidx.test.ext:junit:1.2.1" androidx-test-espresso = "androidx.test.espresso:espresso-core:3.6.1" google-material = "com.google.android.material:material:1.12.0" kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" } +moshi-kotlin = { module = "com.squareup.moshi:moshi-kotlin", version.ref = "moshi" } +moshi-codegen = { module = "com.squareup.moshi:moshi-kotlin-codegen", version.ref = "moshi" } robolectric = "org.robolectric:robolectric:4.14.1" [plugins] @@ -29,6 +32,7 @@ android-baseline = { id = "androidx.baselineprofile", version = "1.3.3" } kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } +kotlin-ksp = { id = "com.google.devtools.ksp", version = "2.0.21-1.0.25" } kotlin-samReceiver = { id = "org.jetbrains.kotlin.plugin.sam.with.receiver", version.ref = "kotlin" } gradle-pluginPublish = { id = "com.gradle.plugin-publish", version = "1.3.0" } publicationsReport = { id = "io.github.gmazzo.publications.report", version = "1.2.8" } diff --git a/plugin/src/main/kotlin/io/github/gmazzo/android/test/aggregation/AndroidTestCoverageAggregationPlugin.kt b/plugin/src/main/kotlin/io/github/gmazzo/android/test/aggregation/AndroidTestCoverageAggregationPlugin.kt index 0dba9ac..649363e 100644 --- a/plugin/src/main/kotlin/io/github/gmazzo/android/test/aggregation/AndroidTestCoverageAggregationPlugin.kt +++ b/plugin/src/main/kotlin/io/github/gmazzo/android/test/aggregation/AndroidTestCoverageAggregationPlugin.kt @@ -169,7 +169,7 @@ abstract class AndroidTestCoverageAggregationPlugin : Plugin { } allVariantsSourcesForCoverageReport.configure { main.allKotlinSourceSets.forAll { - from(it.kotlin.srcDirs) + from(it.kotlin) } } allVariantsClassesForCoverageReport.configure {