A plugin to enable the use of Scoverage in a gradle Scala project.
You can find instructions on how to apply the plugin at: http://plugins.gradle.org/plugin/org.scoverage
-
reportScoverage: Produces XML and HTML reports for analysing test code coverage. -
aggregateScoverage: An experimental support for aggregating coverage statistics in composite builds.When applied on a project with sub-projects, the plugin will create the aggregation task
aggregateScoverage, which will first generate reports for each project individually (including the parent project), and will then generate an aggregated result based on these reports.The aggregated report will override the parent-project specific report (
parent-project/build/reports/scoverage).One can still use
reportScoveragein order to generate a report without aggregation. -
checkScoverage: Validates coverage status according to generated reports (aggregated or not).gradle checkScoveragewill automatically invokereportScoveragebut it won't generate aggregated reports. In order to check coverage of aggregated reports one should usegradle checkScoverage aggregateScoverage.
The plugin exposes multiple options that can be configured by setting them in an scoverage block within the project's
build script. These options are as follows:
-
scoverageVersion = <String>(default"1.3.1"): The version of the scoverage scalac plugin. This (gradle) plugin should be compatible with all 1+ versions. -
scoverageScalaVersion = <String>(default"2.12"): The scala version of the scoverage scalac plugin. This will be overridden by the version of thescala-librarycompile dependency (if the dependency is configured). -
coverageOutputCobertura = <boolean>(defaulttrue): Enables/disables cobertura.xml file generation (for both aggregated and non-aggregated reports). -
coverageOutputXML = <boolean>(defaulttrue): Enables/disables scoverage XML output (for both aggregated and non-aggregated reports). -
coverageOutputHTML = <boolean>(defaulttrue): Enables/disables scoverage HTML output (for both aggregated and non-aggregated reports). -
coverageDebug = <boolean>(defaultfalse): Enables/disables scoverage debug output (for both aggregated and non-aggregated reports). -
minimumRate = <double>(default0.75): The minimum amount of coverage in decimal proportion (1.0== 100%) required for the validation to pass (otherwisecheckScoveragewill fail the build). -
coverageType = <"Statement" | "Branch" | "Line">(default"Statement"): The type of coverage validated by thecheckScoveragetask. For more information on the different types, please refer to the documentation of the scalac plugin (https://github.com/scoverage/scalac-scoverage-plugin).
By default, running any of the plugin tasks will compile the code both using "normal" compilation (compileScala)
and using the scoverage scalac plugin (compileScoverageScala).
In cases where you only wish to generate reports / validate coverage, but are not interested in publishing the code,
it is possible to only compile the code with the scoverage scalac plugin, thus reducing build times significantly.
In order to do so, simply add the arguments -x compileScala to the gradle execution.
For example: gradle reportScoverage -x compileScala.
-
No more
testScoveragetask; instead,testwill run coverage whenever the build is invoked with any of the scoverage tasks. -
No more need to declare scalac dependencies:
// can safely delete this from build scripts
dependencies {
scoverage group: 'org.scoverage', name: 'scalac-scoverage-plugin_2.12', version: '1.3.1'
scoverage group: 'org.scoverage', name: 'scalac-scoverage-runtime_2.12', version: '1.3.1'
}- All configurations are configured in
scoverageblock. For instance:
// do this
scoverage {
minimumRate = 0.5
}
// instead of this
checkScoverage {
minimumRate = 0.5
}- No more need to declare aggregation task:
// can safely delete this from build scripts
task aggregateScoverage(type: org.scoverage.ScoverageAggregate)
checkScoverage {
reportDir = file("$buildDir/scoverage-aggregate")
}