Is there a way to run a gradle task always when al...
# community-support
m
Is there a way to run a gradle task always when all the tasks finish? (to clean up) I'm thinking android studio but this is most probably generic question for gradle. If not, I'll ask in android channel.
m
You can use a BuildService and
BuildService.close()
. It's not a task but you can do cleanups there.
I guess you could do tasks shenanigans as well such as
Copy code
tasks.configureEach {
  if (this != cleanupTask) {
    finalizedBy(cleanupTask)
  }
}
1
m
this later appeals more to me as it can be done in a plugin
so, I'd basically say that all tasks are finalized by my cleanup one and my cleanup will run at the end of everything, right?
m
I think so but try it out. I like the
BuildService
one better personally because it keeps your task graph simple. You can also register
BuildService
in plugins
m
ah, does it happen that you have a simple code that would do that within plugin (simpler is always better)
(or just pointers would be helpful)
m
I have this BuildService for an example. I wouldn't say it's simple but if what you're trying to express is "cleanup after a build", it's probably more idiomatic
m
thanks a ton
m
But "idiomatic" is a strong word so do whatever floats your boat
m
yup
m
oh, awesome, this fits my scenario even better
awesome help from both, thanks again