我想从Jacoco生成的代码覆盖率报告中排除GreenDao框架生成的文件,这些文件放在一个名为dao的包中,但创建一个像下面这样的自定义任务并不奏效。
def coverageSourceDirs = [
'../app/src/main/java'
task jacocoTestReport(type: JacocoReport, dependsOn: "testDebug") {
group = "Reporting"
description = "Generate Jacoco coverage reports after running tests."
reports {
xml.enabled = true
html.enabled = true
classDirectories = fileTree(
dir: './build/intermediates/classes/debug',
excludes: ['**/R*.class',
'**/*$InjectAdapter.class',
'**/*$ModuleAdapter.class',
'**/Dao*.class',
'**/*$ViewInjector*.class'
sourceDirectories = files(coverageSourceDirs)
executionData = files("$buildDir/jacoco/testDebug.exec")
// Bit hacky but fixes https://code.google.com/p/android/issues/detail?id=69174.
// We iterate through the compiled .class tree and rename $$ to $.
doFirst {
new File("$buildDir/intermediates/classes/").eachFileRecurse { file ->
if (file.name.contains('$$')) {
file.renameTo(file.path.replace('$$', '$'))
这里是我的build.gradle。
apply plugin: 'com.android.application'
android {
jacoco {
version = '0.7.3.201502191951'
testOptions {
unitTests.returnDefaultValues = true
compileSdkVersion 22
buildToolsVersion '22.0.1'
defaultConfig {
applicationId "com.nitralabs.m1_mm"
minSdkVersion 12
targetSdkVersion 18
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
debug {
testCoverageEnabled = true
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
dependencies {
compile 'com.google.code.gson:gson:2.1'
compile files('libs/greendao-1.3.1.jar')
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:recyclerview-v7:22.2.0'
testCompile 'org.mockito:mockito-core:1.10.19'
testCompile 'org.hamcrest:hamcrest-library:1.1'
compile 'junit:junit:4.12'
compile 'org.apache.commons:commons-io:1.3.2'
testCompile 'com.android.support.test:testing-support-lib:0.1'
testCompile 'junit:junit:4.12'
androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.5.2'
如何在不创建自定义任务的情况下将某些类或包从代码覆盖中排除?
谢谢你的帮助。