title: Gradle variable scoping
body: <p>I my root project I defined a variable and a method using it like</p>
  
  <pre><code>// An immediately executed closure (I hope)
  def myvar = ({-&gt; do something})()
  
  def myfun() {
      println myvar + ":" + project
  }
  </code></pre>
  
  <p>and called it in a subproject. This lead to an error like</p>
  
  <blockquote>
    <p>Could not find property 'myvar' on root project 'root'.</p>
  </blockquote>
  
  <p>I find it strange as <code>myvar</code> is in scope on the function definition (so I'm probably doing something different?). Ii looks like dynamic scoping, but I can't believe it.</p>
  
  <p>I know about <code>project.ext</code>, but I don't want to make <code>myvar</code> available elsewhere.</p>
  
  <p>So I moved the definition into the declaration (it gets evaluated multiple times now, but who cares), but then I found out that <code>project</code> refers to the root project, rather than the subproject calling the function (lexical scoping). Can I get the current project without passing it explicitly?</p>