Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/398.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java gradle测试和主设置相同_Java_Gradle - Fatal编程技术网

Java gradle测试和主设置相同

Java gradle测试和主设置相同,java,gradle,Java,Gradle,出于各种原因不值得讨论,但我认为这是非常重要的——我只希望有一个源代码集——java源代码,并将测试放在其中——但我不知道如何使用gradle 如果我将测试源集指向同一目录,我会收到错误消息,说两个源集不能共享同一根 gradle中有没有简单的方法让“测试”任务只使用主源集?结果比我想象的要简单,方法完全不同,只需添加一个新的测试任务 task mainTest( type: Test ) { description = "Runs tests embedded in the code"

出于各种原因不值得讨论,但我认为这是非常重要的——我只希望有一个源代码集——java源代码,并将测试放在其中——但我不知道如何使用gradle

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


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

结果比我想象的要简单,方法完全不同,只需添加一个新的测试任务

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;

结果证明比我想象的要简单,采用了完全不同的方式,只添加了一个新的测试任务

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;

我猜想,离开这里的保留地有点值得讨论,因为这种方法是非常非正统的。尽管测试可能倾向于在其工件中泄漏更敏感的内容,但您将同时发布源代码和测试代码。你想完成什么?我们这样编码:我们这样编码:类Blah{public static class Tests{//Tests of Blah…}//guts of Blah…}-出于很多原因,它们更像一本小书,不能容纳512个字符。没有额外的发布,因为过滤掉所有*$Tests.class是件小事——但从根本上说——不管你同意还是不同意这种风格——我想知道如何让gradle做到这一点?我猜想,在这里放弃保留是有点值得讨论的,因为这种方法是非常非正统的。尽管测试可能倾向于在其工件中泄漏更敏感的内容,但您将同时发布源代码和测试代码。你想完成什么?我们这样编码:我们这样编码:类Blah{public static class Tests{//Tests of Blah…}//guts of Blah…}-出于很多原因,它们更像一本小书,不能容纳512个字符。没有额外的发布,因为过滤掉所有*$Tests.class是件小事——但从根本上说——不管你同意还是不同意这种风格——我想知道如何让gradle做到这一点?