Multi-project test dependencies with gradle

mathd picture mathd · Apr 13, 2011 · Viewed 79.2k times · Source

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.

Answer

Fesler picture Fesler · Nov 1, 2011

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.