我有一个多模块项目,其中一个添加了一个 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
但还没有真正接近解决方案。