我有一个多模块项目,其中一个项目添加了一个sourceSet以支持3个源文件夹
apply plugin: 'groovy'
apply plugin: 'java'
configurations {
componentTestCompile.extendsFrom compile, testCompile
componentTestRuntime.extendsFrom runtime, testRuntime, componentTestCompile
}
sourceSets {
componentTest {
java {
srcDir 'src/componentTest/java'
}
groovy {
srcDir 'src/componentTest/groovy'
}
resources {
srcDir 'src/componentTest/resources'
}
compileClasspath = sourceSets.main.output + configurations.componentTestCompile
runtimeClasspath = output + compileClasspath + configurations.componentTestRuntime
}
}
task componentTest(type: Test) {
testClassesDir = sourceSets.componentTest.output.classesDir
classpath = sourceSets.componentTest.runtimeClasspath
reports.html.destination = file("$reports.html.destination/component")
reports.junitXml.destination = file("$reports.junitXml.destination/component")
println classpath
}
check.dependsOn componentTest
执行gradle componentTest时,不编译Java代码(构建目录未填充相应的类文件)。 但是,当将上述sourceSet应用于简单项目(单个模块)时,它可以工作。我在弄清问题是什么时有点迷失。我一直在玩表达式
compileClasspath = sourceSets.main.output + configurations.componentTestCompile
runtimeClasspath = output + compileClasspath + configurations.componentTestRuntime
但实际上还没有能够更接近解决方案。