title: Gradle - how to run the tests from a different gradle project and still get coverage data
body: <p><strong>Does anyone know how to run the tests from a different gradle project and still get emma coverage reporting data?</strong></p>
  
  <p>Here is my current layout:</p>
  
  <pre><code>Root/
    settings.gradle (no explicit build.gradle - just defines all subprojects)
    SubProjectA/
      build.gradle
      src/ (all real source is here)
    SubProjectATest/
      build.gradle
      src/ (all testing code is here)
    SubProjectB/ (similar structure as A)
    SubProjectBTest/ (similar structure as ATest)
  </code></pre>
  
  <p>I am currently using the emma plugin, and I would like to build <em>SubProjectA</em> and run all the tests in <em>SubProjectATest</em> from within the build.gradle of <em>SubProjectA</em>.  </p>
  
  <p>Here are some things I tried inside the build.gradle of SubProjectA</p>
  
  <ol>
  <li><code>testCompile project(':SubProjectATest').sourceSets.test.classes</code> (<a href="https://stackoverflow.com/questions/5144325/gradle-test-dependency">as suggested by this article</a>), but I got an error "<code>Could not find property 'sourceSets' on project</code>"</li>
  <li>Just the straight-up <code>testCompile project(':SubProjectATest')</code>, but then I get "<code>..SubProjectA/build/classes/test', not found</code>" and also "Skipping task '<code>:SubProjectA:compileTestJava' as it has no source files.</code>"</li>
  <li><p>Simply adding a sourceSet like the following:</p>
  
  <p>test {
   java {
     srcDir '../SubProjectATest/src'
   }
  }</p></li>
  </ol>
  
  <p><strong>Adding the source set in (option 3)</strong> is the only option that worked, but it seems sloppy to do it this way.  Does anyone know how to do this using project dependencies?</p>
  
  <p><strong>Update #1</strong>
  I also tried one of the answers below to use test.dependsOn and the tests do run, but the <em>emma</em> plugin reported the following:  <code>build/classes/test', not found</code></p>