Multi-project integration test dependencies

I have a multi-project build where subprojects can be dependent on each other. Some of these projects have integration tests that are separate from the regular unit tests. A simple example script might be:

def integrationTestConfig = {
 configurations {
  integrationTestCompile
  integrationTestRuntime
 }
   sourceSets {
  integrationTest {
   java.srcDir file('src/integrationTest/java')
   resources.srcDir file('src/integrationTest/resources')
  }
 }
   dependencies {
  integrationTestCompile sourceSets.main.output
  integrationTestCompile configurations.testCompile
  integrationTestCompile sourceSets.test.output
  integrationTestRuntime configurations.testRuntime
 }
     task(type: Test, 'integrationTest') {
  testClassesDir = sourceSets.integrationTest.output.classesDir
  classpath = sourceSets.integrationTest.runtimeClasspath
 }
}
  project(":a") {
 apply plugin: "java"
 configure(project, integrationTestConfig)
}
  project(":b") {
 apply plugin: "java"
 configure(project, integrationTestConfig)
 dependencies {
  compile project(":a")
 }
}
  project("c") {
apply plugin: "java"
 configure(project, integrationTestConfig)
 dependencies {
  compile project(":b")
 }
 }

The catch is that the integration tests in “:c” are dependent on compile integration test code in “:b” and “:a”. I’d like to add code to integrationTestConfig to automatically adds this functionality.

Any suggestions on how to do this?

In a nutshell, you’ll have to Jar up the code to be shared, declare a configuration, add the Jar as an artifact of the configuration, and depend on the configuration via a project dependency. This question has been asked several times before, so you should find code samples here or on Stack Overflow.