title: How can I make sure that an included subproject runs before the main project in Gradle?
body: <p>I have two Gradle projects with the following directory structure:</p>
  
  <pre><code>/baseDir
    /first
    /first/build.gradle
    /second 
    /second/build.gradle
    /second/settings.gradle
  </code></pre>
  
  <p>settings.gradle looks like this: </p>
  
  <pre><code>includeFlat "first"
  </code></pre>
  
  <p>When I do <code>gradle build</code> the second project is compiled after the first (main) project. I tried in the first project's build.gradle:</p>
  
  <pre><code>dependencies {
    compile project(':first')
  }
  </code></pre>
  
  <p>When doing <code>gradle build</code> I get an error that dependencies declared in the first project could not be found in the second one. </p>
  
  <p>What I need is the following. When I do <code>gradle build</code>on the second project I want that the first project will be build first and that <code>first.jar</code> is used as a dependency in the second project.</p>
  
  <p><strong>How can I do that?</strong></p>
  
  <p>Edit: When I set the following in my second project's settings.gradle: </p>
  
  <pre><code>includeFlat "first", "second"
  </code></pre>
  
  <p>then I get the following error while doing <code>graddle clean</code>:</p>
  
  <pre><code>FAILURE: Build failed with an exception.
  
  * What went wrong:
  Could not select the default project for this build. Multiple projects in this build have project directory '/Users/mg/Documents/Grails/GGTS3.6.3-SR1/second': [:, :second]
  &gt; Multiple projects in this build have project directory '/Users/mg/Documents/Grails/GGTS3.6.3-SR1/second': [:, :second]
  
  * Try:
  Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
  
  BUILD FAILED
  </code></pre>
  
  <p>Edit: I create a sample project form demonstration: <a href="https://github.com/confile/Gradle-MultiProject-Test" rel="nofollow">https://github.com/confile/Gradle-MultiProject-Test</a></p>