One for the Gradle experts here: A Gradle plugin (...
# community-support
t
One for the Gradle experts here: A Gradle plugin (https://github.com/autonomousapps/dependency-analysis-gradle-plugin) uses a generated source set from another plugin (https://github.com/JetBrains/compose-multiplatform/blob/7ddb0a73fae275023ee3dbc713[…]n/org/jetbrains/compose/resources/ComposeResourcesGeneration.kt) and the upstream plugin, Compose Multiplatform, seems to do everything right by first giving the registered task the
OutputDirectory
annotated property
codeDir
a provider from the project layout and then map the task property to the
srcDir
of the source set it contributes code to. Still, Gradle responds with
Reason: Task ':app:explodeCodeSourceMyVariant' uses this output of task ':app:generateActualResourceCollectorsForAndroidMain' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.
(https://youtrack.jetbrains.com/issue/CMP-7283). So why does implicit task wiring not work here? Because the
zip
operator is used instead of
map
? Because
srcDir
is called with
listOf()
(I guess to have a sane default if sources should not be generated, so
emptyList()
can act as fallback)?
j
Do you own some of those tasks? I mean, have you created some of them?
m
This looks related to https://github.com/autonomousapps/dependency-analysis-gradle-plugin/issues/1002 but for compose instead of Antlr 🤔
It might be a Gradle bug? Or maybe
.zip
doesn't carry over task dependencies?
Ah wait, I remember now! I think it's the same issue as this one I filed some time ago: https://issuetracker.google.com/u/1/issues/376709932
Mmmm but this one is AGP only while there's (apparently) no AGP involved here....
In a simple example,
zip
seems to carry task dependencies:
Copy code
abstract class MyTask: DefaultTask() {
  @get:InputFiles
  abstract val inputFiles: ConfigurableFileCollection

  @get:OutputFile
  abstract val outputFile: RegularFileProperty

  @TaskAction
  fun taskAction() {
    outputFile.get().asFile.parentFile.mkdirs()
    outputFile.get().asFile.writeText("hello" + inputFiles.files.single().readText())
  }
}

val producer = tasks.register("producer", MyTask::class.java) {
  inputFiles.from(file("settings.gradle.kts"))
  outputFile = file("build/producerOutput")
}

val shouldGenerateCode = provider { true }

val consumer = tasks.register("consumer", MyTask::class.java) {
  inputFiles.from(producer.zip(shouldGenerateCode) { file, flag ->
    if (flag) listOf(file) else emptyList()
  })
  outputFile = file("build/consumerOutput")
}
So the dependency is lost... somewhere
t
Thanks for the AGP/KGP issue link, linked that to my issue. Seems less and less to be an issue of neither of the plugins I'm using here...
@Javi No, I own neither.
v
What Gradle version are you using? Before 7.2 there was indeed a Gradle bug that
zip
looses task dependencies, but that was fixed in 7.2-RC2.
👀 1
m
Can you even run compose with Gradle 7.2?
v
🤷‍♂️
🤷 1
t
I'm on 8.10.1
👍 1