title: Gradle configuration for multi-module project with shared dependencies
body: <p>Make a first project with gradle, so i look at spring, gradle, hibernate projects how they organize gradle files, and start make my own. But, can't find mistake, why my configuration doesn't work. (sub-projects cant resolve dependency)
  So <strong>project tree</strong>:</p>
  
  <pre><code>Root project 'foobar'
  +--- Project ':foobar-app'
  | +--- Project ':foobar-app:people'
  | | +--- Project ':foobar-app:people:people-api'
  | | +--- Project ':foobar-app:people:people-core'
  | | +--- Project ':foobar-app:people:people-data'
  | | \--- Project ':foobar-app:people:people-rest'
  | \--- Project ':foobar-app:realtor'
  +--- Project ':foobar-starter'
  \--- Project ':foobar-system'
  +--- Project ':foobar-system:foobar-system-jpa'
  +--- Project ':foobar-system:foobar-system-neo4j'
  +--- Project ':foobar-system:foobar-system-persistence'
  +--- Project ':foobar-system:foobar-system-repository'
  \--- Project ':foobar-system:foobar-system-tx'
  </code></pre>
  
  <p>The problem, when i make foobar-system-jpa.gradle file with set of dependences, etc, it's not work - no dependecies can be reach for this module. But when in root 'foobar' build.gradle make a set of deps for 'foobar-system-jpa' subproject - it' work fine. Why?</p>
  
  <p>My root <strong>build.gradle</strong>:</p>
  
  <pre><code>configurations.all {
      // check for updates every build
      resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
  }
  
  configure(allprojects) { project -&gt;
      group = 'com.foobar'
      version = '0.0.1-SNAPSHOT'
  
      apply from: "${rootDir}/dependencies.gradle"
  
      apply plugin: 'maven'
      apply plugin: 'idea'
  
      ext.gradleScriptDir = "${rootProject.projectDir}/gradle"
  
      apply from: "${gradleScriptDir}/task.gradle"
  
  }
  
  configure(subprojects) { subproject -&gt;
      apply plugin: 'java'
  
      sourceCompatibility = 1.7
      targetCompatibility = 1.7
      apply from: "${rootDir}/dependencies.gradle"
  
      repositories {
          mavenCentral()
  
          maven { url "http://m2.neo4j.org/" }
          maven { url "http://repo.maven.apache.org/maven2" }
      }
  
  
      dependencies {
          testCompile (libs.junit)
          testCompile (libs.mockito)
          testCompile group: 'org.hamcrest', name: 'hamcrest-library', version: '1.3'
      }
  
  }
  </code></pre>
  
  <p>my <strong>dependecies.gradle</strong></p>
  
  <pre><code>ext {
      springVersion = "4.0.0.RELEASE"
      jUnitVersion = "4.11"
      hibernateVersion = "4.2.1.Final"
  
      libs = [
              //springframework
              spring_core: "org.springframework:spring-core:$springVersion",
              spring_orm: "org.springframework:spring-orm:$springVersion",
            ......
              hibernate_entitymanager: "org.hibernate:hibernate-entitymanager:$hibernateVersion",
              hibernate_persistence: "org.hibernate.javax.persistence:hibernate-jpa-2.0-api:1.0.1.Final",
              //database
              postgresql : "org.postgresql:postgresql:9.3-1100-jdbc41",
              commons_dbcp : "commons-dbcp:commons-dbcp:1.4",
             .....
  
      ]
  }
  </code></pre>
  
  <p>and my <strong>settings.gradle</strong>  </p>
  
  <pre><code>rootProject.name = 'foobar'
  include ':foobar-system:foobar-system-jpa'
  ....
  include ':foobar-app:people:people-rest'
  include ':foobar-app:people:people-core'
  ....
  include ':foobar-starter'
  
  project(':foobar-system:foobar-system-jpa').projectDir = "$rootDir/foobar-system/foobar-system-jpa" as File
  project(':foobar-system:foobar-system-repository').projectDir = "$rootDir/foobar-system/foobar-system-repository" as File
  .....
  project(':foobar-app').projectDir = "$rootDir/foobar-app" as File
  project(':foobar-starter').projectDir = "$rootDir/foobar-starter" as File
  
  rootProject.children.each { project -&gt;
      project.buildFileName = "${project.name}.gradle"
      assert project.projectDir.isDirectory()
      assert project.buildFile.exists()
      assert project.buildFile.isFile()
  }
  </code></pre>
  
  <p>So, foobar-system-jpa.gradle <em>that NOT work</em> (module can not compile, cause not found any dependency)</p>
  
  <pre><code>dependencies {
      compile libs.spring_orm
      compile (libs.spring_data_jpa) {
          exclude(module: 'spring-jdbc')
          exclude(module: 'spring-orm')
      }
      compile libs.hibernate_entitymanager
      compile libs.postgresql
      compile libs.commons_dbcp
      compile project(':foobar-system:foobar-system-tx')
  }
  </code></pre>
  
  <p>Thank you for reply. For inspiration a take a look for this project <a href="https://github.com/hibernate/hibernate-orm/blob/master/hibernate-entitymanager/hibernate-entitymanager.gradle">https://github.com/hibernate/hibernate-orm/blob/master/hibernate-entitymanager/hibernate-entitymanager.gradle</a></p>
  
  <p>UPD: remove some not necessary code </p>