title: Nested object inside custom plugin extension
body: <p>I'm developing a custom Gradle plugin and I want to define a configuration closure (plugin extension) like this:</p>
  
  <pre><code>myplugin {
     property1 'value'
  
     property2 {
       a1 'hello'
       a2 'bye'
     }
  }
  </code></pre>
  
  <p>I have this classes:</p>
  
  <pre><code>public class MyPluginExtension { //root extension
  
      String property1;
      Property2 peroperty2;
  
      //getters and setters
  }
  
  public class Property2 {
      String a1;
      String a2;
      //getters and setters
  }
  </code></pre>
  
  <p>And, in the plugin project, I create the extension this way:</p>
  
  <pre><code>project.getExtensions().create("myplugin", MyPluginExtension.class);
  </code></pre>
  
  <p>But in my client project, when I apply and configure the plugin like shown above, I get this error:</p>
  
  <blockquote>
    <p>Gradle DSL method not found: 'property2()'</p>
  </blockquote>
  
  <p>How can I define the <code>property2</code> closure in my <code>MyPluginExtension</code> class?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I have tried this:</p>
  
  <pre><code> public class MyPluginExtension { //root extension
  
      String property1;
      Property2 peroperty2;
  
          //getters and setters
  
      public void property2(Closure c) {
          c.setResolveStrategy(Closure.DELEGATE_FIRST);
          c.setDelegate(property2);
          c.call();
      }
  }
  </code></pre>
  
  <p>But now I get this error:</p>
  
  <blockquote>
    <p>Gradle DSL method not found: a1()</p>
  </blockquote>
  
  <p>It can't resolve nested closure fields.</p>