title: Trying to include Gradle project as dependency, but include() not working
body: <p>I have a Gradle project which depends on another Gradle project. My project structure is like this:</p>
  
  <ul>
  <li>project1
  
  <ul>
  <li>build.gradle</li>
  <li>settings.gradle</li>
  <li>src/</li>
  </ul></li>
  <li>project2
  
  <ul>
  <li>build.gradle</li>
  <li>settings.gradle</li>
  <li>src/</li>
  </ul></li>
  </ul>
  
  <p>in <code>project1/build.gradle</code> I want to add <code>project2</code> as a dependency:</p>
  
  <pre><code>version '1.0-SNAPSHOT'
  
  apply plugin: 'java'
  apply plugin: 'eclipse'
  apply plugin: 'idea'
  
  sourceCompatibility = 1.8
  
  repositories {
      mavenCentral()
  }
  
  sourceSets {
      main {
          java {
              srcDirs = [ 'src' ]
          }
      }
  }
  
  include ':project2'
  project(':project2').projectDir = new File("../project2")
  
  dependencies {
      compile project(':project2')
  }
  </code></pre>
  
  <p>Unfortunately, I'm always getting this error message:</p>
  
  <blockquote>
    <p>Error:(21, 0) Could not find method include() for arguments [:project2] on root project 'project1' of type org.gradle.api.Project.</p>
  </blockquote>
  
  <p>I'm using Gradle 3.5 and I'm getting this error both on the command line (<code>gradle build</code>) and in IntelliJ. I found a few StackOverflow threads about the same issue (<a href="https://stackoverflow.com/questions/26886259/could-not-find-method-include-for-arguments-app-on-root-project-android-stu">this</a> and  <a href="https://stackoverflow.com/questions/38544093/could-not-find-method-include-for-arguments-app-on-root-project-myproject">this</a>), but they were not helpful.</p>
  
  <p>The <a href="https://docs.gradle.org/current/userguide/multi_project_builds.html" rel="nofollow noreferrer">Gradle multi-project documentation</a> also doesn't mention any specific requirements which I may be missing that can cause the error.</p>
  
  <p>When I leave the <code>include</code> call out, I get the message that the project path could not be found in the root project.</p>
  
  <p>I also tried moving the dependency to a subdirectory of <code>project1</code>, but without success.</p>
  
  <p>I wonder what I'm doing wrong and why apparently not many other people are having the same problem. I'd be grateful for hints.</p>
  
  <p>Note: this is not an Android project.</p>