Source code on github: https://github.com/kendarorg/Gradle101
Create a new project demo006, java application with JUnit 4 and package "org.kendar"
Now you can see into the dependencies the following part, JUnit. You could then use the same idea from the previous parts if you have a multimodule project: adding the subprojects/afterEvaluate pattern, and a variable to declare the dependency version
dependencies {
...
testImplementation 'junit:junit:4.12'
}
You can then run "gradle test" and...magic happens.
Add then the jacoco plugin in the build.gradle
plugins {
...
id 'jacoco'
}
And declare the JaCoCo version with the directory to use for the reports
jacoco {
toolVersion = "0.8.5"
}
Then you can configure JaCoCo output
jacocoTestReport {
reports {
xml.enabled false
csv.enabled false
html.destination file("${buildDir}/jacocoHtml")
}
}
And the rules to break the builds if coverage is not met. Whiting this a rule has been added to exclude gradle stuffs
jacocoTestCoverageVerification {
violationRules {
rule {
limit {
minimum = 0.5
}
}
rule {
enabled = false
element = 'CLASS'
includes = ['org.gradle.*']
limit {
counter = 'LINE'
value = 'TOTALCOUNT'
maximum = 0.3
}
}
}
}
Then running "gradle clean check jacocoTestReport" You will generate the report into "demo006\build\jacocoHtml" dir