2

I have a multi-module gradle project and I want to make use of some of the test classes from the shared module in my dependent module.

dependencies {
    compile project(':shared-module')

    testCompile project(':shared-module'), classifier: 'test-jar'
}

The first dependency works, but the testCompile dependency does not work. I cannot seem to find the syntax for it. The maven equivalent would be:

<dependency>
    <groupId>${project.groupId}</groupId>
    <artifactId>shared-module</artifactId>
    <version>${project.version}</version>
    <type>test-jar</type>
    <scope>test</scope>
</dependency>
troymass
  • 1,022
  • 3
  • 11
  • 24

2 Answers2

2

You can do

dependencies {
    compile project(':shared-module')
    testCompile project(path: ':shared-module', configuration: 'testRuntime') 
} 
lance-java
  • 25,497
  • 4
  • 59
  • 101
  • 2
    Won't work with Gradle 4 [Java library](https://docs.gradle.org/current/userguide/java_library_plugin.html) plugin (replaces Java plugin). `testImplementation` or `testRuntimeOnly` are not consumable. – Abhijit Sarkar May 14 '18 at 06:58
0

You could use the nebula test jar plugin

Note Nebula have deprecated this plugin as they believe test utilities should live in their own project. I tend to agree with them

lance-java
  • 25,497
  • 4
  • 59
  • 101