I have three tasks:
The DoSomeStuff has a finalizeBy ‘Cleanup’ command. This works fine.
I also want the same thing for “PublishResults”, but I only want to do this if PublishResults was set to execute already. I.E. if the developer has decided he wants to publish results, it will do it even if DoSomeStuff ends up failing.
I tried adding a block of code that executed when the task graph was ready, and used graph.hasTask(‘PublishResults’) and if that returned true, executing finalizedBy(‘PublishResults’).
In this case, it is obvious that once the task graph is ready, it has no effect. Is there another way to accomplish this?
I really want to avoid running PublishResults, because it is not used often by developers, but by a build agent. Today, I have to add the finalizedBy statement statically, which means I have to have the developers tell Gradle to skip that PublishResults task (-x PublishResults).
The only other option I have come up with is to use an onlyIf block, and do this based on a property, that is false by default, and the user can override when necessary.