Hi all. This might be more of a <#C19FD9681|gradle...
# multiplatform
x
Hi all. This might be more of a #gradle question than #multiplatform, but I have this task that generate api & models in my
commonMain
Copy code
openApiGenerate {
  generatorName.set("kotlin")
  library.set("multiplatform")
  ...
}
By default this task doesn’t
dependOn
to run before any build task, so I had to manually do so
Copy code
tasks.preBuild { dependsOn(tasks.openApiGenerate) }
This works for
android
, but for desktop i had to do
Copy code
tasks.named("compileKotlinDesktop") { dependsOn(tasks.openApiGenerate) }
so forth for all other targets. Is there a common task that I can hook on to instead?
e
if you added its output to the appropriate sourceSet through the proper mechanisms (which happens automatically with task output properties, or manually with
files(...).builtBy(...)
) then it all just works automatically and you should not need any explicit task dependencies
https://github.com/ephemient/kotlin-numeric/blob/main/build.gradle.kts for example has two custom tasks that are added to sourceSets.commonMain.kotlin and Gradle automatically generates before compiling
and yes, this is definitely more of a #gradle question than a #multiplatform or kotlin question
x
I have
Copy code
sourceSets {
    val commonMain by getting {
      // include build open-api definitions
      kotlin.srcDir("$buildDir/openapi/src/commonMain")
    }
  }
doesnt look like task is in the task graph by default 🤔 even the docs say
if you’re generating the code on compile, you can add these as a dependency to 
compileJava
 or any other existing task…
Copy code
compileJava.dependsOn buildKotlinClient, tasks.openApiGenerate
dont think
compileJava
task exist in a multiplatform module, so just wondering if there is an equivalent
e
.srcDir("string") definitely loses the task dependency
it should be .srcDir(DirectoryProperty) or something similar, or fall back to building your own ConfigurableFileCollection if their plugin doesn't use the proper Gradle APIs
… looks like they don't, so
Copy code
srcDir(openApiGenerate.outputDir.flatMap { files(it).builtBy(tasks.openApiGenerate)) })
or something along those lines
x
thanks let me try this out
maybe the multiplatform template author @andrewemery has any recommendation 🤔
doesn’t look like they are on this slack