在 gradle 中,我创建了一个新的 sourceSet
用于服务测试,如下所示:
sourceSets{
servicetest{
java.srcDirs = [//path to servicetests]
}
}
这个源集依赖于 TestNG,所以我希望通过做类似的事情来降低依赖性:
dependencies{
servicetest(group: 'org.testng', name: 'testng', version: '5.8', classifier: 'jdk15')
}
不幸的是,这会返回一个错误。有什么方法可以为特定的 sourceSet
声明依赖关系,还是我运气不好?
最佳答案
最近的 Gradle 版本自动为每个源集“foo”创建和连接配置“fooCompile”和“fooRuntime”。
如果您仍在使用旧版本,您可以声明自己的配置并将其添加到源集的 compileClasspath 或 runtimeClasspath 中。像这样的东西:
configurations {
serviceTestCompile
}
sourceSets {
serviceTest {
compileClasspath = configurations.serviceTestCompile
}
}
dependencies {
serviceTestCompile "org.testng:testng:5.8"
}
关于java - 有没有办法为 gradle 中新创建的源集指定依赖项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8791977/