Reputation: 1549
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.
Upvotes: 1
Views: 2146
Reputation: 1549
After digging into it some more:
sourceSets sourceSets.main
which addressed nearly all issues I had. Files in build/classes were no longer wiped.Fixed build.gradle:
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 {
sourceSets sourceSets.main // important!
executionData fileTree(project.rootDir.absolutePath).include("**/build/jacoco/*.exec")
afterEvaluate {
classDirectories = files(classDirectories.files.collect {
fileTree(dir: it, exclude: ['**/path/to/package/*'])
})
}
}
Upvotes: 0