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>
masstroy
  • 862
  • 1
  • 8
  • 22

2 Answers2

2

You can do

dependencies {
    compile project(':shared-module')
    testCompile project(path: ':shared-module', configuration: 'testRuntime') 
} 
lance-java
  • 21,832
  • 3
  • 45
  • 81
  • 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
  • 21,832
  • 3
  • 45
  • 81