Search code examples
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:

  • Project A

    • -> src/main/java
    • -> src/test/java
  • Project B

    • -> src/main/java (depends on src/main/java on Project A)
    • -> src/test/java (depends on src/test/java on Project A)

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.