I'd like to generate some code for `commonMain` in...
# ksp
e
I'd like to generate some code for
commonMain
in a multiplatform project, is this supported? Because I only see the following configurations
configuration ':ksp'
configuration ':kspJvm'
configuration ':kspJvmTest'
configuration ':kspMetadata'
configuration ':kspNative'
configuration ':kspNativeTest'
1
g
You can use
kspMetadata
to generate code in commonMain.
p
However it doesn't setup the compile tasks, I think evant posted a workaround in one of the issues
e
thanks all for your tips and help 🙂
I still don't have the nice Idea resolution though (generated code appears unresolved -red- but compilations succedes), did you manage to get it working?
g
Works good for me (when the entire project is building at least). Also I've an additional line in the build.gradle config for Idea:
Copy code
val commonMain by getting {
    kotlin.srcDir("build/generated/ksp/commonMain/kotlin")
}
e
yeah, I just noticed after I cleaned and rebuilt once again
also, you can write also simply
tasks.withType<KotlinCompile<*>>
instead
tasks.withType<KotlinCompile<*>>().all
p
That's my configure block:
Copy code
dependencies {
  add("kspMetadata", project(":processor:codegen"))
  add("kspMetadata", project(":processor:swiftgen"))
}
// workaround for <https://github.com/google/ksp/issues/567>
kotlin.sourceSets.commonMain {
  kotlin.srcDir("build/generated/ksp/commonMain/kotlin")
}
// workaround for <https://github.com/google/ksp/issues/567>
tasks.withType<org.jetbrains.kotlin.gradle.dsl.KotlinCompile<*>>().all {
  if (name != "kspKotlinMetadata") {
    dependsOn("kspKotlinMetadata")
  }
}
But it's bad because the .all kills lazy task configuration
e
do we want lazy cfg in there?
p
It won't work
At least when I tried