title: Scope of the extra properties in Gradle?
body: <p>I have a Gradle script similar to this:</p>
  
  <pre><code>ext {
    dir = null
  }
  
  task init &lt;&lt; {
    build()
  }
  
  task buildAll(type: Exec){
    workingDir ext.dir
    commandLine 'cmd', '/c', "echo %JAVA_HOME%"
  }
  
  def build(){
    ext.dir = "asdf"
    buildAll.execute()
  }
  </code></pre>
  
  <p>When I run the script, I get:</p>
  
  <pre><code>groovy.lang.MissingPropertyException: Cannot get property 'dir' on extra properties extension as it does not exist
  </code></pre>
  
  <p>Whatever I tried, I couldn't get a task to read a property from "ext". It can be seen from methods (like "build()" in my example), but not from any other task except the default one ("init" in my example).</p>
  
  <p>I understand that the "ext" properties should be accessible from anywhere inside the project, so what am I doing wrong?</p>
  
  <p><strong>UPDATE:</strong>
  The workflow I'm trying to achieve (as asked by Opal):</p>
  
  <p>I have several environments I need to build with one script. Each of these environments is listed in a CSV file with a line: <code>&lt;environment&gt;,&lt;version&gt;</code>.</p>
  
  <p>Script then needs to do the following:</p>
  
  <ul>
  <li>Delete existing directory</li>
  <li>Checkout code from SVN into new directory (both directory and SVN url depend on environment and version)</li>
  <li>Copy some settings files (paths depend on version)</li>
  <li>Edit some of those settings files (values depend on environment and version)</li>
  <li>Set some environment variables (JAVA_HOME, ANT_HOME...) (depends on version)</li>
  <li>Run three build commands (<code>${ANT_HOME}/bin/ant -f $checkedOutCodeDirectory/Build/build-all.xml target1</code>, then <code>target2</code> and <code>target3</code>)</li>
  </ul>
  
  <p>This needs to be executed for each environment</p>