Skip to content

Instantly share code, notes, and snippets.

@MarkyMarkMcDonald
Last active December 15, 2015 12:35
Show Gist options
  • Save MarkyMarkMcDonald/876132a2c7deafe7a4f0 to your computer and use it in GitHub Desktop.
Save MarkyMarkMcDonald/876132a2c7deafe7a4f0 to your computer and use it in GitHub Desktop.
Exposing Test Helpers across components in a gradle multi-module project

To produce a jar containing test sources and use it elsewhere in a Gradle multi-module project (component A depends on component B):

Create a new configuration in component A:

// components/A/build.gradle
configurations {
    test-helpers
}

Add a jar task with the source sets that configuration needs:

// components/A/build.gradle
task factoryJar(type: Jar) {
    appendix = "test-helpers"
    from sourceSets.test.output
    from sourceSets.main.output
}

Declare that jar as an artifact for that configuration:

// components/A/build.gradle
artifacts {
    test-helpers factoryJar
}

Declare a dependency on component A, specifying the factory configuration

// components/B/build.gradle
testCompile project(path: ":components/A", configuration: 'test-helpers')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment