javagradlebuilddependenciesmulti-project

Multi-project test dependencies with gradle


I have a multi-project configuration and I want to use gradle.

My projects are like this:

My Project B build.gradle file is like this:

apply plugin: 'java'
dependencies {
  compile project(':ProjectA')
}

The task compileJava work great but the compileTestJava does not compile the test file from Project A.


Solution

  • Deprecated - For Gradle 5.6 and above use this answer.

    In Project B, you just need to add a testCompile dependency:

    dependencies {
      ...
      testCompile project(':A').sourceSets.test.output
    }
    

    Tested with Gradle 1.7.