I need to check the minimum coverage with the new jacoco task
jacocoTestCoverageVerification
This task is available with in the 3.4.1 gradle release and with the jacoco plugin >= 0.6.3
I could run another task that generates an html report with the branch coverage but now I want to use that number to make the build fail.
This is my code
buildscript {
ext {
....
}
repositories {
mavenCentral()
maven {
....
}
}
dependencies {
.....
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'jacoco'
jar {
baseName = "coverage-test"
}
dependencies {
// my dependencies
}
eclipse {
classpath {
containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8'
}
}
wrapper {
gradleVersion = '3.4.1'
}
jacoco {
toolVersion = '0.7.9'
}
jacocoTestReport {
reports {
xml.enabled false
csv.enabled false
}
group = "Reporting"
description = "Generate Jacoco coverage reports after running tests."
additionalSourceDirs = files(sourceSets.main.allJava.srcDirs)
afterEvaluate {
classDirectories = files(classDirectories.files.collect {
fileTree(
dir: it,
excludes:
[
'com/jacoco/dto/**',
'com/jacoco/configs/**',
//and others
])
})
}
}
jacocoTestCoverageVerification {
//I tried this and it didn't work
// classDirectories = files(classDirectories.files.collect {
// fileTree(
// dir: it,
// excludes:
// [
// 'com/jacoco/dto/**',
// 'com/jacoco/configs/**',
// //and others
// ])
// })
violationRules {
rule {
//Also tried this and it didn't work
// excludes = ['com/jacoco/dto/**', ...]
limit {
counter = 'BRANCH'
minimum = 0.8
}
}
}
}
check.dependsOn jacocoTestCoverageVerification
With classDirectories I get the following error Cannot get property 'files' on null object. And with the second option (only excludes), the build run smoothly but It doesn't exclude any class.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…