Add task to end of all other tasks


(Eric Deandrea) #1

Is there a way to add a task to the very end of the task graph? Basically no matter which tasks the user executed, I always want to append another task to the very end of the task graph.


(Stephane Galles) #2

Maybe with the ‘buildFinished’ callback : http://gradle.org/docs/current/javadoc/org/gradle/api/invocation/Gradle.html#buildFinished(groovy.lang.Closure)


(Eric Deandrea) #3

That won’t work, as the build has already completed. I want to add a task to the execution so that it is executed at the end of the build. Once execution has completed I can’t add other tasks to the task graph.


(Stephane Galles) #4

Indeed, The callback won’t allow you to add a new task but it may allow you to execute any code you want. The same code that you would have used in the task. But maybe I don’t see the big picture here.


(Eric Deandrea) #5

The big picture is that gradle already has my entire model with all of my task (& multi-module build dependencies) built in - i want the task to be able to reference what all of my custom plugins are doing. I don’t want to exec out to some other process.


(Luke Daley) #6

You can add to the start parameter…

gradle.startParameter.taskNames << “endTask”

That’s off the top of my head, so the properties may not be named correctly.


(Eric Deandrea) #7

I see where you are going with this…Basically adding the task(s) I want executed as if the user had specified them. I’ll give it a try. Is there a specific place where I would need to do this? I would like this to be handled by my custom plugins, so would doing this inside the apply method of my plugin class work? Would it have to be inside a project.afterEvaluate {} block?


(Luke Daley) #8

I’d have it as the first line in your ‘apply(Project)’ implementation.

Generally avoid ‘afterEvaluate’ unless you absolutely need it.


(Eric Deandrea) #9

This does seem to work when added to a buildscript directly - gradle.startParameter.taskNames << ‘eclipse’.

Whatever tasks I execute the eclipse task is always appended to the end. I have not tried it via way of my custom plugins yet, but I expect it should work as well.

Thanks for the help!