This message was deleted.
# community-support
s
This message was deleted.
v
Actually, I greatly dislike the advice in the error to add explicit dependencies with
dependsOn
or
mustRunAfter
as these are in 98.7 % of cases just symptom treatment. (number made up)
You usually should make sure outputs are properly wired to inputs.
In case of generated sources, the generating task should properly define its outputs and then the task itself configured as
srcDir
on the source directory set.
๐Ÿ‘๐Ÿผ 1
a
hi ๐Ÿ‘‹ Can you share more about this bit?
The example is a plugin that generates sources in build/generated and adds the path to the main source set
Is this a plugin you control? Do you know how it's adding the sources? My guess is that it's not adding a new srcDir by mapping the generation task? E.g.
Copy code
// build.gradle.kts

sourceSets {
  main {
    resources {
      // add a new resource dir that is produced by the generation task
      srcDir(myCodeGenerationTask.map { it.temporaryDir })
    }
  }
}
v
This way every consumer of sources automatically has the necessary task dependency.
t
Itโ€™s an Android SourceSet that right now receives the path like this:
Copy code
sourceSets.getByName("main") {
    kotlin.srcDir("$buildDir/generated/source/api/src/main/kotlin")
}
The task that fills the directory with things is setup like this:
Copy code
tasks.withType<GenerateTask>().configureEach {
    generatorName.set("kotlin")
    outputDir.set("$buildDir/generated/source/api")
    ...
}
I guess this is the culprit then, since itโ€™s a hard-wired path and not a
DirectoryProperty
. Even more so, the plugin has the
outputDir
defined as
Property<String>
Would
Property<String>
wiring suffice here or would Gradle still complain then?
a
I'm pretty sure Gradle will convert a String into a file, though a DirectoryProperty would help with dev-ex. The main things are to make sure
outputDir
is marked with
@OutputDirectory
and that the generation tasks are converted to file-providers and added as SrcDirs to the Android SourceSet, so Gradle will be able to figure out the task dependencies
t
Luckily, it is, thanks for the help!
๐Ÿ‘ 1
v
I darkly remember that with Android things might be a bit different and you somehow need to additionally register tasks as source generation tasks or something like that. But I might remember wrongly or it might have changed in the past. I don't do Android dev.