https://kotlinlang.org logo
Title
n

Norbi

04/26/2023, 2:31 PM
I've found the following configuration in the documentation:
dependencies {
    add("kspCommonMainMetadata", project(":test-processor"))
    add("kspJvm", project(":test-processor"))
    add("kspJvmTest", project(":test-processor"))
}
But how should I configure KSP to process classes in
src/commonTest/kotlin
?
kspCommonTestMetadata
does not seem to exist...
Besides, KSP does not seem to process in
src/jvmTest/kotlin
with the above configuration. But if I move the file to
src/jvmMain/kotlin
everything works as expected.
I'm really confused after I found this 🙂: https://github.com/google/ksp/issues/1365
p

Pavel Lahoda

04/27/2023, 6:50 PM
Hey Norbi, is it really working for you? You get your common code processed and the generated code is placed correctly? If so, would you mind to share your setup? Thanks
n

Norbi

04/28/2023, 4:29 PM
@Pavel Lahoda This works for me currently for my actual project setup:
dependencies {
    add("kspCommonMainMetadata", project(":test-processor"))
}

tasks.withType<KotlinCompile<*>>().all {
    if (name != "kspCommonMainKotlinMetadata") {
        dependsOn("kspCommonMainKotlinMetadata")
    }
}

kotlin.sourceSets.commonMain {
    kotlin.srcDir("build/generated/ksp/metadata/commonMain/kotlin")
}
e

edwinRNDR

05/01/2023, 11:35 AM
This is exactly the nugget of information I needed to get my multi platform KSP experiment going.
p

Pavel Lahoda

05/01/2023, 11:59 AM
I got it running as well. Found a problem, that there are actually two variants of KotlinCompile, org.jetbrains.kotlin.gradle.tasks.KotlinCompile and org.jetbrains.kotlin.gradle.dsl.KotlinCompile. The former is the correct one to use - at least that was the source of problems for me.