Is it possible to have a task run multiple times in a single taskgraph


For my build, I have a case where a task A is a pre-condition to multiple tasks (B,C). Task A needs to run each time B and C are run.

If B and C are in the same task graph, can I create an execution like: A,B,A,C ?

(Luke Daley) #2

No. Tasks only ever execute once in a build.

(Perryn Fowler) #3

Hi wolfdown,

Would you mind explaining why you want to do this?

cheers Perryn


I found a work around, which was to create a closure and then apply that to doFirst methods of each task.

The reason I need this is because I have two conflicting sub-tasks of my build, and I need to do a cleanup before the second task is run. This cleanup step is also part of my default ‘clean’ task. This created the error where: ‘gradle clean; gradle build’ would run successfully, but ‘gradle clean build’ would fail. I do not want ‘clean build’ to fail because that is a very common command call.