Francisco Prieto
05/09/2025, 2:53 PMproject.tasks.register
, and it does it inside the onVariants
lambda provided by AGP.
One of these tasks has to search for another task by name, access its outputs, and map them as an input. Something like this:
val targetTaskProvider = project.tasks.named("targetTask") // some task created by another plugin
val myTask = project.tasks.register(...) { task ->
task.input.set(targetTaskProvider.flatMap { // do some processing on task outputs }
}
When using project.tasks.named
, if the task I’m looking for has not been registered yet, it will fail to find it. I found that wrapping everything in project.afterEvaluate
will ensure that the task is already there, but it doesn’t seem optimal. Is there any other alternative?Francisco Prieto
05/09/2025, 2:54 PMproject.provider {}
so it’s not searched for immediately?Vampire
05/09/2025, 3:01 PMMartin
05/09/2025, 3:01 PMVampire
05/09/2025, 3:01 PMafterEvaluate
does not ensure anyhting, the main earnings for using it are timing problems, ordering problems and race conditionsVampire
05/09/2025, 3:02 PMprovider { ... }
you loose task dependenciesVampire
05/09/2025, 3:03 PMVampire
05/09/2025, 3:03 PMpluginManager.withPlugin("...") { ... }
to react to that other plugin being applied.Martin
05/09/2025, 3:04 PMfinalizeDsl{}
might also workVampire
05/09/2025, 3:04 PMafterEvaluate
to register that task, that is usually the way to go.Vampire
05/09/2025, 3:04 PMMartin
05/09/2025, 3:04 PMMartin
05/09/2025, 3:05 PMFrancisco Prieto
05/09/2025, 3:08 PMbundle[Variant]JsAndAssets
or createBundle[Variant]JsAndAssets
, depending on the RN version, and I need to get the index.android.bundle
file from its outputMartin
05/09/2025, 3:10 PMFrancisco Prieto
05/09/2025, 3:10 PMMartin
05/09/2025, 3:11 PMfinalizeDsl()
. It should be a tiny bit better that afterEvaluate{}
https://github.com/android/gradle-recipes/blob/dd275c878633c4ad272883d4bc70f1ab3c8[…]DslFinalize/build-logic/plugins/src/main/kotlin/CustomPlugin.ktVampire
05/09/2025, 3:12 PMMartin
05/09/2025, 3:12 PMafterEvaluate{}
a lot themselves, you might have to rely on it as well, which is not great but 🤷Vampire
05/09/2025, 3:12 PMFrancisco Prieto
05/09/2025, 3:12 PMtasks.named
alternative that doesn’t eagerly look for the task?Martin
05/09/2025, 3:12 PMafterEvaluate{}
Vampire
05/09/2025, 3:13 PMVampire
05/09/2025, 3:13 PMMartin
05/09/2025, 3:13 PMis there aalternative that doesn’t eagerly look for the task?tasks.named
tasks.configureEach {
if (name == "foo"){
// do your stuff here
}
}
Martin
05/09/2025, 3:14 PMYeah, so still, different name, same problems 🙂Kindof at least you have only one plugin to worry about
Vampire
05/09/2025, 3:14 PMMartin
05/09/2025, 3:15 PMVampire
05/09/2025, 3:15 PMnamed
to configure the found task, but to depend on the found taskVampire
05/09/2025, 3:16 PMtasks.named { }.configureEach { }
or tasks.matching { }.configureEach { }
.
But neither is helpful for depending without breaking task-configuration avoidanceMartin
05/09/2025, 3:17 PMtasks.all{}
😅Martin
05/09/2025, 3:17 PMVampire
05/09/2025, 3:17 PMVampire
05/09/2025, 3:17 PMMartin
05/09/2025, 3:17 PMMartin
05/09/2025, 3:18 PMFrancisco Prieto
05/09/2025, 3:24 PM