Reputation: 1109
In gradle I have created a new sourceSet
for service testing like this:
sourceSets{
servicetest{
java.srcDirs = [//path to servicetests]
}
}
This source set depends on TestNG, so I was hoping to pull the dependency down by doing something like:
dependencies{
servicetest(group: 'org.testng', name: 'testng', version: '5.8', classifier: 'jdk15')
}
Unfortunately this returns an error. Is there any way to declare a dependency for a specific sourceSet
or am I out of luck?
Upvotes: 6
Views: 11591
Reputation: 20129
The following works for Gradle 1.4.
apply plugin: 'java'
sourceCompatibility = JavaVersion.VERSION_1_6
sourceSets {
serviceTest {
java {
srcDir 'src/servicetest/java'
}
resources {
srcDir 'src/servicetest/resources'
}
compileClasspath += sourceSets.main.runtimeClasspath
}
}
dependencies {
compile(group: 'org.springframework', name: 'spring', version: '3.0.7')
serviceTestCompile(group: 'org.springframework', name: 'spring-test', version: '3.0.7.RELEASE')
serviceTestCompile(group: 'org.testng', name:'testng', version:'6.8.5')
}
task serviceTest(type: Test) {
description = "Runs TestNG Service Tests"
group = "Verification"
useTestNG()
testClassesDir = sourceSets.serviceTest.output.classesDir
classpath += sourceSets.serviceTest.runtimeClasspath
}
Upvotes: 4
Reputation: 123910
Recent Gradle versions automatically create and wire configurations 'fooCompile' and 'fooRuntime' for each source set 'foo'.
If you are still using an older version, you can declare your own configuration and add it to the source set's compileClasspath or runtimeClasspath. Something like:
configurations {
serviceTestCompile
}
sourceSets {
serviceTest {
compileClasspath = configurations.serviceTestCompile
}
}
dependencies {
serviceTestCompile "org.testng:testng:5.8"
}
Upvotes: 9