commandLine in Exec doesn't get executed right away


I have the following tasks defined. Although the tasks are executed in the order of dependency, I notice that the actual execution of the commands didn’t get executed until println statements of the subsequent tasks got printed. In this case, the brew install didn’t happen until removeOldAssets. Would you please tell me why and how I can fix it? Thank you.

task removeR2M(type:Exec){
    ignoreExitValue true
    commandLine 'brew','remove','r2m'
    println "Removing r2m (if exists)"
  task installR2M(type:Exec){
    commandLine 'brew','install',''
    println "Installing r2m"
installR2M.dependsOn removeR2M
  task removeOldAssets(type: Delete) {
    delete fileTree(dir: workingDir + '/app/src/androidTest/java/com/magneteng/r2m/assets')
    println "Removing old assets"
removeOldAssets.dependsOn installR2M

Platform: Mac 10.9.5 Gradle: 1.11

To make the printlns part of task execution (rather than task configuration), you need to wrap them with ‘doLast { … }’. For more information, see “56.1. Build phases” in the Gradle User Guide.