How to run some task after exec task completed?


(Sergey Smirnov) #1

Hi, I have a build scripts:

defaultTasks "rasterize"
  task rasterize(type:Exec) {
     workingDir "./"
     executable "adl.exe"
     args [
          "app.xml",
          "swf2xml"
     ]
       doLast {
          onRasterizationComplete();
     }
}
  void onRasterizationComplete() {
     result = rasterize.getExecResult();
}

and it works!

But how run some task after complete exec process instead a method? like a:

defaultTasks "printResult"
  task rasterize(type:Exec) {
     workingDir "./"
     executable "adl.exe"
     args [
          "app.xml",
          "swf2xml"
     ]
}
  task printResult {
     result = rasterize.getExecResult();
}
  printResult.dependsOn rasterize

The printResult task printed ‘null’ before the rasterize task completed… why? and how I can resolve it?


(Peter Niederwieser) #2

It’s the classical configuration phase vs. execution phase pitfall. Your code is configuring the ‘printResult’ task, and all configuration happens before any execution. What you really want is to add a task action:

task printResult {
  dependsOn rasterize
  doLast { // add a task action
    println rasterize.execResult
  }
}

(Sergey Smirnov) #3

Thanks, now understood )