apply plugin: 'java' apply plugin: 'jacoco' buildscript { repositories { mavenCentral() jcenter() } } repositories { jcenter() } jacocoTestReport { reports { xml { enabled true // coveralls plugin depends on xml format report } html { enabled true } } test { jacoco { destinationFile = file("$buildDir/jacoco/jacocoTest.exec") classDumpFile = file("$buildDir/jacoco/classpathdumps") excludes = ["projecteuler/**"] // <-- does not work // excludes = ["projecteuler"] } } }
官方论坛上找到了这个答案!
jacocoTestReport { afterEvaluate { classDirectories.setFrom(files(classDirectories.files.collect { fileTree(dir: it, exclude: 'com/blah/**') })) } }
来源: https ://issues.gradle.org/browse/GRADLE-2955
对于旧的 gradle 版本 < 5.x 可能需要使用 classDirectories = files(classDirectories.files.collect {而不是classDirectories.setFrom
classDirectories = files(classDirectories.files.collect {
classDirectories.setFrom
build.gradle
apply plugin: 'java' apply plugin: 'jacoco' jacocoTestReport { reports { xml { enabled true // coveralls plugin depends on xml format report } html { enabled true } } afterEvaluate { classDirectories = files(classDirectories.files.collect { fileTree(dir: it, exclude: ['codeeval/**', 'crackingthecode/part3knowledgebased/**', '**/Chapter7ObjectOrientedDesign**', '**/Chapter11Testing**', '**/Chapter12SystemDesignAndMemoryLimits**', 'projecteuler/**']) }) } }
如您所见,我成功地添加了更多内容exclude:以过滤一些包。
exclude:
来源: https ://github.com/jaredsburrows/CS-Interview- Questions/blob/master/build.gradle
apply plugin: 'jacoco' task jacocoReport(type: JacocoReport) { reports { xml { enabled true // coveralls plugin depends on xml format report } html { enabled true } } afterEvaluate { classDirectories = files(classDirectories.files.collect { fileTree(dir: it, exclude: ['codeeval/**', 'crackingthecode/part3knowledgebased/**', '**/Chapter7ObjectOrientedDesign**', '**/Chapter11Testing**', '**/Chapter12SystemDesignAndMemoryLimits**', 'projecteuler/**']) }) } }
来源: https ://github.com/jaredsburrows/android-gradle-java-app- template/blob/master/gradle/quality.gradle#L59