Jacob Rhoda
06/20/2024, 6:34 PMbuild.gradle.kts
setup:
plugins {
alias(libs.plugins.kotlin.multiplatform)
alias(libs.plugins.kotlin.native.cocoapods)
alias(libs.plugins.android.library)
alias(libs.plugins.skie)
alias(libs.plugins.ksp)
}
kotlin {
...
sourceSets {
commonMain {
kotlin.srcDir("build/generated/ksp/commonMain/kotlin")
...
}
}
}
dependencies {
add("kspCommonMainMetadata", libs.arrow.opticsKspPlugin)
configurations
.filter { it.name.startsWith("ksp") && it.name != "ksp" }
.forEach {
add(it.name, libs.arrow.opticsKspPlugin)
}
}
kotlin.sourceSets.commonMain {
kotlin.srcDir("build/generated/ksp/metadata/commonMain/kotlin")
}
I'm noticing that when I build for Android, it generates the common code in build/generated/ksp/android/androidDebug/kotlin/...
, instead of in a commonMain
folder, and I end up with unresolved reference
errors when I try to build. When I have Android Studio build just the common
code, it generates it in the commonMain
folder, but then I have an error about duplicate symbols. Do I need to change something with how KSP is set up in my config to support the new compiler?
Versions: Kotlin 2.0.0, KSP 2.0.0-1.0.22, Arrow: 1.2.4.Jiaxiang
06/21/2024, 10:50 PMJacob Rhoda
06/24/2024, 4:23 PMcommonMain
folder? Otherwise, I'm going to have to somehow tell Gradle to look in other generated folders for that generated code which doesn't seem right to me. Also, if I remove the kotlin.srcDir("build/generated/ksp/commonMain/kotlin")
line, it doesn't find anything.Jacob Rhoda
06/24/2024, 6:45 PMcommonMain
source set.
kotlinExtension.sourceSets.named("commonMain").configure { kotlin.srcDir("${layout.buildDirectory.get()}/generated/ksp/metadata/commonMain/kotlin")
}
tasks.withType(KotlinCompilationTask::class.java).configureEach {
if (name != "kspCommonMainKotlinMetadata") {
dependsOn("kspCommonMainKotlinMetadata")
}
}
Adapting for my build.gradle.kts...
kotlin.sourceSets.commonMain {
kotlin.srcDir("${layout.buildDirectory.get()}/generated/ksp/metadata/commonMain/kotlin")
}
project.afterEvaluate {
tasks.withType(KotlinCompilationTask::class.java).configureEach {
if (name != "kspCommonMainKotlinMetadata") {
dependsOn("kspCommonMainKotlinMetadata")
}
}
It would be really nice if this were better documented somewhere.Jiaxiang
06/24/2024, 8:09 PMJacob Rhoda
06/25/2024, 3:36 PMJiaxiang
06/25/2024, 6:01 PMJacob Rhoda
06/25/2024, 6:04 PM