Home:ALL Converter>gradle jacoco with integrationTest and exclusions

gradle jacoco with integrationTest and exclusions

Ask Time:2018-06-20T00:03:56         Author:fabien

Json Formatter

I am using the gradle jacoco plugin to get by coverage reports for tests and integration tests. Sources for the integration tests are defined with the test-sets plugin. To get both tests and integration tests covered in the report, I deduced from this post that I should call executionData with an include on *.exec files. Now, I am trying to figure out how I can exclude a single class from the jacoco report (and analysis). Filter JaCoCo coverage reports with Gradle points to using afterEvaluate and alter the classDirectories, but this generates an empty report when I use it.

plugins {
    id 'org.unbroken-dome.test-sets' version '1.5.0'
}

apply plugin: 'java'
apply plugin: 'jacoco'

sourceSets {
    main {
        java {
            srcDirs = ['jsrc']
        }
    }
}

testSets {
    integrationTest {
        dirName = 'integration-test'
    }
}

jacocoTestReport {
    executionData fileTree(project.rootDir.absolutePath).include("**/build/jacoco/*.exec")
    // commented because causes the report to be empty
    //afterEvaluate {
    //    classDirectories = files(classDirectories.files.collect {
    //        fileTree(dir: it, exclude: ['**/TheOneClassToExclude.*'])
    //    })
    //}
}

In case this matters, I am using gradle 4.4 with JDK7.

Author:fabien,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/50932619/gradle-jacoco-with-integrationtest-and-exclusions
yy