title: Using Gradle, how can I print how long each task took to execute?
body: <p>Right now, for one of the gradle targets run frequently, the output looks like this:</p>
  
  <pre>
  :DataPlanner:clean
  :common:clean
  :server:clean
  :simulator:clean
  :util:clean
  :util:compileJava
  :util:processResources UP-TO-DATE
  :util:classes
  :util:compileTestJava
  :util:processTestResources
  :util:testClasses
  :util:test
  :util:jar
  :common:compileJava
  :common:processResources UP-TO-DATE
  :common:classes
  :common:compileTestJava
  :common:processTestResources
  </pre>
  
  <p>How do I get it to look something more like this?</p>
  
  <pre>
  :DataPlanner:clean
  took 2secs
  :common:clean
  took 2 secs
  :server:clean
  took 3 secs
  :simulator:clean
  took 4 secs
  :util:clean
  took 1 sec
  ...
  </pre>
  
  <p>If it's not possible to get every task to print its duration upon completion, printing the timestamp would be an acceptable alternative.  </p>
  
  <p>Any ideas?</p>
  
  <p>Modifying one of the proposed solutions which didn't work for me, this one did:</p>
  
  <pre><code>gradle.taskGraph.beforeTask { Task task -&gt;
  task.ext.setProperty("startTime", new java.util.Date())
  }
  
  gradle.taskGraph.afterTask { Task task, TaskState state -&gt;
      int secs = ( new java.util.Date().getTime() - task.ext.startTime.getTime() ) / 1000
      int mins = secs / 60
  
      if ( 4 &lt; secs ) {
          int sec = secs - mins * 60
          println " -&gt; took " + mins + ( ( 1 == mins ) ? " min " : " mins " ) + sec + ( ( 1 == sec ) ? " sec" : " secs" )
      }
  }
  </code></pre>