Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gradle doLast philosophy

Tags:

In a gradle build file, there are multiple ways to specify the items executed for a particular task. the doFirst method puts a task item on the top of the task stack, so that the item is executed before the rest of the task stack. This is very handy if you need to do some preparatory items before the main task. In fact, if you call doFirst several times, the item added in the last call is the first thing executed.

In theory, doLast should be doing something similar, but doLast should get called AFTER the main execution of the task is complete. But, in gradle 1.2, if you call doLast and then add something to the main task after doLast in the gradle.build file, the main task item is the last item called. For example, the following gradle build file:

task myTask  myTask << {     println "myTask main execution block" }  myTask.doFirst { println "myTask doFirst call one" }  myTask.doFirst {     println "myTask doFirst call two" }  myTask.doLast {     println "myTask doLast" }  myTask << {     println "myTask more main execution block" } 

Produces the following output:

:myTask myTask doFirst call two myTask doFirst call one myTask main execution block myTask doLast myTask more main execution block  BUILD SUCCESSFUL  Total time: 1.585 secs 

My question is this: Is it the intent of doLast to simply append steps onto the end of the task (like doFirst tacks on to the beginning)? If so, doLast seems pointless with the exception of providing symmetry with doFirst. A user can simply do myTask << {...} to append something on to the end. I would have thought that doLast would make sure that any "doLast" items would be done after the main execution block.

Is this simply the way gradle's doLast is supposed to work, or is this a bug?? (or am I just stupid for appending something onto the main execution block after calling doLast -- which was a simple mistake after tacking in another execution block).

like image 243
user1691701 Avatar asked Nov 21 '12 23:11

user1691701


People also ask

What does doLast mean in gradle?

doFirst(action) Adds the given Action to the beginning of this task's action list. doLast(action) Adds the given closure to the end of this task's action list. The closure is passed this task as a parameter when executed.

How Gradle task works?

Gradle has different phases, when it comes to working with the tasks. First of all, there is a configuration phase, where the code, which is specified directly in a task's closure, is executed. The configuration block is executed for every available task and not only, for those tasks, which are later actually executed.


1 Answers

<< is an alias for doLast, so everything works as expected here.

like image 183
Peter Niederwieser Avatar answered Sep 28 '22 10:09

Peter Niederwieser