title: Gradle error: Could not find method add() for arguments
body: <p>I'm using gradle <strong>2.12</strong> and I have a multi-module <strong>java</strong> gradle project structured in the following manner - </p>
  
  <pre><code>parentProject  
  |__module1  
     |__src  
     |__build.gradle  
  |__module2  
     |_src  
     |__build.gradle  
  |__build.gradle
  </code></pre>
  
  <p>The settings.gradle is defined as - </p>
  
  <pre><code>include "module1"
  project(":module1").projectDir = file("path/to/module1")
  
  include "module2"
  project(":module2").projectDir = file("path/to/module2")
  </code></pre>
  
  <p>module2 depends on module1 and the dependency is required in the buildscript. I followed <a href="https://gist.github.com/clmarquart/1976155" rel="nofollow noreferrer">this</a> example which shows a workaround as gradle doesn't allow classpath dependencies of projects in the buildscript. What I did in module2's build.gradle is - </p>
  
  <pre><code>buildscript {
      repositories {
          mavenLocal()
      }
  
      project.getTasks().add([name: "module1", type: GradleBuild]) {
          buildFile = '../module1/build.gradle'
          tasks = ['pluginJar']
      }.execute()
  }
  
  apply plugin: java
  
  dependencies {
      // project specific dependencies
  }
  </code></pre>
  
  <p>I started getting the following error - </p>
  
  <pre><code>Error:(13, 0) Could not find method add() for arguments [{name=module1, type=class org.gradle.api.tasks.GradleBuild}, build_c3cjs9wfepa1xdklituv2tk9i$_run_closure1$_closure3@51bcefbf] on task set.
  </code></pre>
  
  <p>I searched for similar errors and found <a href="https://stackoverflow.com/questions/37870567/add-sourcesjar-task-to-custom-gradle-plugin">this</a> solution, but it didn't help me.</p>
  
  <p>This is how my project structure is, and I cannot change it to make module1 an independent build.</p>
  
  <p>Please advice. Appreciate your help!</p>
  
  <p>Thanks</p>