Gradle, Jacoco and 90% Code Coverage

With Jacoco Gradle Plugin it is easy to setup your project to enforce a coverage percentage.

I use the following configuration to enforce 90% both at class and at project level.

plugins {
    ...
	id('jacoco')
}

...
..
.

check {
	dependsOn jacocoTestCoverageVerification
}
jacocoTestReport {
	dependsOn test
}
jacocoTestReport {
	reports {
		xml.enabled false
		csv.enabled false
	}
}
jacocoTestCoverageVerification {
    violationRules {
	    rule {
		    limit {
			    minimum = 0.9
		    }
	    }
	    rule {
		    element = 'CLASS'
		    excludes = ['example.micronaut.Application']
		    limit {
			    minimum = 0.9
		    }
	    }
    } 
}

The above example excludes the Application class.

Yes, I use Apache Groovy Gradle DSL.

Tags: #test #gradle #jacoco
Apr 2021, 29.

 

My next events:
🗓 Oct 05 17:00 Jumpstart your Java applications with AWS Lambda and Micronaut