简体   繁体   English

gradle测试和主设置相同

[英]gradle test and main sets the same

For various reasons not worth getting into a discussion about, but that I think are very important - I would like to only have one source set - the java source, and have the tests be in that - but I can't figure out how to do it with gradle. 由于各种原因,不值得讨论,但是我认为这很重要-我只想设置一个源-java源,并进行测试-但我不知道该怎么做。用gradle来做。

If I point the test sourceset at the same directory - I get errors saying two source sets can't share the same root. 如果将测试源集指向同一目录,则会收到错误消息,说两个源集不能共享同一根目录。

Is there any easy way in gradle to just tell the "test" task to just use the main sourceset? gradle中有什么简单的方法可以告诉“ test”任务仅使用主源集?

turns out to be easier than I thought, going a completely different way and just adding a new test task 原来比我想象的要容易,采用了完全不同的方式,只是添加了新的测试任务

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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM