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.

My next events:
๐Ÿ—“ May 27 09:00 AWS Dublin - Micronaut and AWS Lambda
๐Ÿ—“ Jul 20 09:00 Workshop Security in the Micronaut Framework
๐Ÿ—“ Sep 20 09:00 JCON Online 2022 - Getting Started with the Micronaut Framework
๐Ÿ—“ Sep 23 09:00 JCON Online 2022 - Micronautยฎ Framework and Microstream Java-native persistence engine

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