Gradle doFirst() Execution Order


How is the order of the doFirst method determined in a gradle build script? I have the following sample script that contains two doFirst methods. I understand that they are additive, as they both execute, but the order that this occurs looks backward:

task initialize task depTask(dependsOn: initialize) initialize { doFirst { println 'processing doFirst in initialization (configuration)' } println 'processing initialize (configuration)' } depTask { println 'processing depTask (configuration)' } depTask << { println 'executing depTask (execution)' } initialize << { println 'executing initialize (execution)' } initialize.doFirst { println 'executing doFirst on initialize (execution)' }

The output from this script is:

processing initialize (configuration) processing depTask (configuration) executing doFirst on initialize (execution) processing doFirst in initialization (configuration) executing initialize (execution) executing depTask (execution)

The first "doFirst" function is defined in the initialize task. The second is defined outside of the configuration block. Why doesn't the first instance execute before the second one? The order of execution looks backward. I would have expected the first one, inside the configuration definition, to execute first. Any help understanding this would be appreciated.


initialize { doFirst { ... } } and initialize.doFirst { ... } are the exact same thing. Both statements are inserting an action at the front of the task's action list. Hence the action that gets inserted later (in this case further down in the script) will get executed first.


  • Apache Zeppelin 0.6.1: Run Spark 2.0 Twitter Stream App
  • Segfault when writing to string allocated by db [assembly]
  • Cannot install Protractor 2.0.0 : ENOENT in bufferutil while node-gyp rebuild
  • How to parse array into tuple with aeson?
  • How to model hierarchical data types in Haskell?
  • Enum type not being mapped to DB table
  • sqoop incremental import append mode with timestamp column
  • how do add multi sql dependency to this code?
  • Delayed “rendering” of WPF/Silverlight Dependency Properties?
  • SQL multiple SELECT query with xmlagg function- Data not pulled in the required fashion
  • jQuery UI .sortable() call is slow when applies to thousands of elements
  • IE8 stops network access after 5 long polling request
  • Gerrit will not push. Error: No common ancestry
  • Initialization section of the package
  • Timeout a query
  • MRO with multiple inheritance in python
  • runtime error when linking ffmpeg libraries in qt creator
  • Python PIL to extract number from image
  • Problem with Django using Apache2 (mod_wsgi), Occassionally is “unable to import from module” for no
  • If statement skipping right to else after being called once?
  • Magento site down due to mysql error General error: 1030 Got error -1 from storage engine
  • How can I replace the server in Web Component Tester
  • Optimizing the print function in Matlab
  • Reading a file into a multidimensional array
  • Security issues with PHP's Readfile method
  • converting text file into xml using php?
  • Unable to get column index with table.getColumn method using custom table Model
  • Stop Bash Script if Hive Fails
  • App restarts from wrong activity
  • Does it make sense to call System.gc() and Thread.sleep() when working on Bitmaps?
  • custom UITableViewCell with image for highlighting
  • onBackPressed() not being executed
  • MongoDb aggregation
  • Is there a way to do normal logging with EureakLog?
  • Jetty Server not starting: Unable to establish loopback connection
  • sending/ receiving email in Java
  • ORA-29908: missing primary invocation for ancillary operator
  • Delete MySQLi record without showing the id in the URL
  • How does Linux kernel interrupt the application?
  • Programmatically clearing map cache