title: Gradle: set variable in taskGraph.whenReady
body: <p>My build script has this code:</p>
  
  <pre><code>def includePatchFrom = "WTF?!"
  
  task patchWebXml(type: Exec) {
      executable "perl"
      args "scripts/patch.pl", includePatchFrom
  }
  
  gradle.taskGraph.whenReady { taskGraph -&gt;
      if (taskGraph.hasTask(webtestWar)) {
          includePatchFrom = "resources/webtest"
      }
      else {
          includePatchFrom = "resources/production"
      }
  }
  </code></pre>
  
  <p>If I understand <a href="http://www.gradle.org/docs/current/userguide/tutorial_using_tasks.html" rel="nofollow">http://www.gradle.org/docs/current/userguide/tutorial_using_tasks.html</a> correctly, I should be able to set that <code>includePatchFrom</code> variable in the <code>whenReady</code> closure, but it just keeps its initial value:</p>
  
  <pre><code>...
  :patchWebXml
  ...
  Starting process 'command 'perl''. Working directory: /Users/robert/ Command: perl scripts/patch.pl WTF?!
  Successfully started process 'command 'perl''
  Cannot read WTF?!: No such file or directory at scripts/patch.pl line 43, &lt;$F&gt; line 14.
  :patchWebXml FAILED
  </code></pre>
  
  <p>From println statements I can tell that <code>includePathFrom</code> gets set to the correct value. It seems like the exec task already has used the old value of <code>includePatchFrom</code> and is not affected when the <code>whenReady</code> closure runs.</p>
  
  <p>What am I missing here and how can I use a different patch file depending on whether this is a production or a test build? </p>