gradle测试和主要设置相同

时间:2017-09-26 06:45:56

标签: java gradle

由于各种原因不值得讨论,但我认为非常重要 - 我想只有一个源集 - java源代码,并且测试就在那里 - 但我无法想象如何用gradle做到这一点。

如果我将测试源集指向同一目录 - 我会收到错误,说两个源集不能共享同一个根。

在gradle中有没有简单的方法告诉“测试”任务只使用主要源集?

1 个答案:

答案 0 :(得分:0)

比我想象的更容易,采用完全不同的方式,只是添加一个新的测试任务

task mainTest( type: Test ) {
    description = "Runs tests embedded in the code"
    testClassesDir = sourceSets.main.output.classesDir
    classpath = sourceSets.main.runtimeClasspath
    binResultsDir=file("$buildDir/main-test-results")
    reports {
        html.destination = "$buildDir/reports/main"
        junitXml.destination="$buildDir/reports/main"
    }    
}

check.dependsOn mainTest;