我正在编写一个训练任务,其中包含主源代码集中的一组测试和代码。我还想在单独的 sourceSet 中提供一个示例答案,该答案可以使用单独的任务运行。有没有办法在两个不同的主 soureSet 上运行相同的测试集?
事实证明,
通过从运行时类路径中删除主源代码集,这是可能的,如下所示:
task testAnswers(type: Test) {
description = "Runs tests against the example answer"
testClassesDir = sourceSets.answers.output.classesDir
classpath -= sourceSets.main.runtimeClasspath
classpath += sourceSets.answers.runtimeClasspath
}