0

我是 Gradle 的新手,它对我来说仍然有点神奇。

在我的项目中,我们不使用默认的 sourceDirs,因为我们将不同类型的测试分开:

configure(subprojects) {
    sourceSets {
        test {
            java.srcDir('src/test/unit/java') 
            resources.srcDir('src/test/unit/resources')
        }
        integrationTest {
            java.srcDir('src/test/integration/java') 
            resources.srcDir('src/test/integration/resources')
        }
        concurrencyTest {
            java.srcDir('src/test/concurrency/java') 
            resources.srcDir('src/test/concurrency/resources')
        }
        componentTest {
            java.srcDir('src/test/component/java') 
            resources.srcDir('src/test/component/resources')
        }
    }
}   

我正在尝试配置一个 scala 测试源目录。我的尝试:

apply plugin: 'scala'

configure(subprojects) {
    sourceSets {
        test {
            java.srcDir('src/test/unit/java') 
            scala.srcDir('src/test/unit/scala')
            resources.srcDir('src/test/unit/resources')
        }
 ...

结果:

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\projects\...\build.gradle' line: 109
# note, this is the line "sourceSets {"

* What went wrong:
A problem occurred evaluating root project 'X'.
> Could not find method sourceSets() for arguments [build_5ft63n6d7svimaibmkfq56rbrk$_run_closure4_closure18@573ed6c3] on root project 'X'.

我尝试了其他一些变体,但无法使其正常工作。有人可以帮忙吗?

4

1 回答 1

1

sourceSets扩展是由语言插件添加的,scala但您没有将scala插件应用于子项目。因此错误。

PS:代替configure(subprojects) { ... },您可以使用subprojects { ... }.

于 2012-09-17T06:54:49.363 回答