Skip to content

Commit

Permalink
Merge pull request #141 from careem/fix_ksp_code_generation_for_non-j…
Browse files Browse the repository at this point in the history
…vm_target
  • Loading branch information
minaEweida authored Oct 10, 2023
2 parents faac891 + 20bdb46 commit f0c478d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file.

---
## master
* Fix ksp code generation for non-jvm target

## 2.13.0
* Refactoring publication and configuration logic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,38 @@ class MockingbirdPluginKspDelegate {
// in commonTest. The plugin will add this the code generated at point 1 as source set for common test so that
// this code will be available for each platform and resolvable by the IDE
target.extensions.configure(KotlinMultiplatformExtension::class.java) {
val firstTargetName = targets.first { it.targetName != "metadata" }.targetName
val selectedTargetName =
targets.firstOrNull { it.targetName == "jvm" }?.targetName ?: firstTargetName
sourceSets.getByName("commonTest") {
kotlin.srcDir("build/generated/ksp/$selectedTargetName/${selectedTargetName}Test/kotlin")
val selectedTarget =
targets.firstOrNull { it.preset?.name == "jvm" }
?: targets.firstOrNull { it.preset?.name == "android" }
?: targets.first { it.preset?.name != "metadata" }

val srcDir = if (selectedTarget.preset!!.name == "android") {
"build/generated/ksp/${selectedTarget.name}/${selectedTarget.name}UnitTestRelease/kotlin"
} else {
"build/generated/ksp/${selectedTarget.name}/${selectedTarget.name}Test/kotlin"
}

sourceSets.getByName("commonTest") { kotlin.srcDir(srcDir) }

val kspConfiguration = if (selectedTarget.preset!!.name == "android") {
"ksp${selectedTarget.name.capitalized()}TestRelease"
} else {
"ksp${selectedTarget.name.capitalized()}Test"
}

target.dependencies {
"ksp${selectedTargetName.capitalized()}Test"("com.careem.mockingbird:mockingbird-processor:${BuildConfig.VERSION}")
kspConfiguration("com.careem.mockingbird:mockingbird-processor:${BuildConfig.VERSION}")
}

val kspTask = if (selectedTarget.preset!!.name == "android") {
"kspReleaseUnitTestKotlin${selectedTarget.name.capitalized()}"
} else {
"kspTestKotlin${selectedTarget.name.capitalized()}"
}

tasks.forEach { task ->
if (task.name.contains("Test") && (task is KotlinCompile<*>)) {
task.dependsOn("kspTestKotlin${selectedTargetName.capitalized()}")
task.dependsOn(kspTask)
}
}
}
Expand Down

0 comments on commit f0c478d

Please sign in to comment.