Not purely Gradle thing, related to Android Gradle...
# plugin-development
m
Not purely Gradle thing, related to Android Gradle Plugin but I assume there should be some Android devs here as well. I am developing a gradle plugin and I need to hook its tasks into build pipeline. I want it to be executed on each build but must be after resources are processed. I tried using
onVariants
together with
tasks.named
to make my task dependent on tasks
assemble(CapitalizedVariantName)
and
bundle(CapitalizedVariantName)
to make sure it gets executed whenever I build either apk or app bundle. But apparently the aforementioned tasks are not yet in the task graph at this point. I want to make sure its done right following the configuration avoidance principles and want to ensure tasks are not created when not needed. I thought that maybe artifacts API can be used. In the end I want to produce a file, but the file I want to generate shouldn't be a part of the apk, just a file that should eventually be committed to the repository.
m
yes, afaik the artifacts API is the way to go - you can use it just to consume and don't have to produce anything if your output is unrelated to the apk
v
No idea about Android, but if you only problem is, that the task is not registered yet, use
tasks.named { ... }.configureEach { ... }
, or
tasks.matching { ... }.configureEach { ... }
instead.
m
Thanks @Vampire
tasks.matching
indeed helped 🙏 @madisp I failed using the artifact APIs. It worked to some extent but required me to setup some artificial input/output in the tasks just so they could be registered with
wiredWithFiles
which looked fishy. If you have any good resources for the artifacts API usage please share.
👌 1