title: How to use Gradle to build a JAR that depends on another JAR
body: <p>I have a Eclipse workspace with a declared workset configured to have several projects. Some are to generate JAR files and others are web applications that use those JAR files. In my architecture I have a JAR that will consist of domain core services and another one that depends on the first one that will consist of higher level services. Finally I will have some web applications that use those both JARs.</p>
  
  <p>The first JAR project is build with Gradle, based on the following script</p>
  
  <pre><code>apply plugin: 'java'
  apply plugin: 'eclipse'
  apply plugin: 'application'
  
  repositories {
      mavenLocal()
      mavenCentral();
  }
  
  jar {
      baseName = 'br.ufpr.unidades.dominio'
      version = '0.1.0'
  }
  
  dependencies {
      compile 'org.hibernate:hibernate-core:4.3.7.Final'
  }
  
  task wrapper(type: Wrapper) {
      gradleVersion = '1.11'
  }
  </code></pre>
  
  <p>As anyone can see, it´s a very simple <code>build.gradle</code> file and the build works fine with it. The expected JAR file is generated in the expected destination folder.</p>
  
  <p>Now, here comes the build script for the second JAR:</p>
  
  <pre><code>apply plugin: 'java'
  apply plugin: 'eclipse'
  apply plugin: 'application'
  
  repositories {
      mavenLocal()
      mavenCentral()
  }
  
  jar {
      baseName = 'br.ufpr.unidades.dominio.hibernate'
      version = '0.1.0'
  }
  
  dependencies {
      runtime fileTree(dir: '../dominio/build/libs', include: '*.jar')
      compile 'org.hibernate:hibernate-core:4.3.7.Final'
  }
  
  task wrapper(type: Wrapper) {
      gradleVersion = '1.11'
  }
  </code></pre>
  
  <p>The second file is very similar to the first one, except it has a dependency on generated JAR:</p>
  
  <pre><code>    runtime fileTree(dir: '../dominio/build/libs', include: '*.jar')
  </code></pre>
  
  <p>Eclipse doesn´t show any problems, but when I try to build the second JAR project I get many Class not found error messages, like the one below:</p>
  
  <pre><code>[sts] -----------------------------------------------------
  [sts] Starting Gradle build for the following tasks: 
  [sts]      build
  [sts] -----------------------------------------------------
  :compileJava
  D:\Users\alex\Documents\Eclipse\workspace\unidades\dominio.hibernate\src\main\java\dominio\hibernate\HibernateCargoRepository.java:7: error: package unidades.dominio does not exist
  import unidades.dominio.Cargo;
  </code></pre>
  
  <p>The message is clear: I´m importing a package that is not being found during the build, so the classes such a package has cannot be referenced in my code. Such a package is declared in the first and perfectly generated JAR file. It also is visible under <code>Referenced Libraries</code> item in the Eclipse project, so Gradle was able to find it to reference it in design time, but not to build the second JAR.</p>
  
  <p>After all that, I suspect it´s a dependency management problem, but I can´t see which it is and how to fix it.</p>
  
  <p>Thanks in advance!</p>