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.The plugin automatically creates a
report{Task name}Scoverage
task for each test task in your Gradle build. ThereportScoverage
task will run all test tasks and you can use the individual tasks to run only the desired tests. For example, to run only the unit tests and no other test tasks (e.g., integration tests), you can runreportTestScoverage
. -
aggregateScoverage
: Aggregates 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 plugin must be applied on a sub-project for it to be included in the aggregated; applying the plugin on a project does not automatically apply it on sub-projects.
The aggregated report will override the parent-project specific report (
parent-project/build/reports/scoverage
).One can still use
reportScoverage
in order to generate a report without aggregation. -
checkScoverage
: Validates coverage status according to generated reports (aggregated or not).gradle checkScoverage
will automatically invokereportScoverage
but it won't generate aggregated reports. In order to check coverage of aggregated reports one should usegradle checkScoverage aggregateScoverage
.
Note: The plugin is not compatible with composite builds. For more information, see the relevant issue.
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"2.1.1
): The version of the scoverage scalac plugin. This (gradle) plugin should be compatible with all 1+ versions. -
scoverageScalaVersion = <String>
(defaultdetected
): The scala version of the scoverage scalac plugin. This overrides the version of thescala-library
compile 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 (otherwisecheckScoverage
will fail the build). -
coverageType = <CoverageType.Statement | CoverageType.Branch | CoverageType.Line>
(defaultCoverageType.Statement
): The type of coverage validated by thecheckScoverage
task. For more information on the different types, please refer to the documentation of the scalac plugin (https://github.com/scoverage/scalac-scoverage-plugin). -
excludedFiles = <files>
(defaultnot set
): Comma separated list of regexes for files to exclude from coverage. -
excludedPackages = <packages, classes and modules>
(defaultnot set
): Comma separated list of regexes for packages, classes and modules to exclude from coverage.
It is possible to configure multiple checks; for instance, one check for a statement rate and another for a branch rate:
scoverage {
check {
minimumRate = 0.5
coverageType = CoverageType.Statement
}
check {
minimumRate = 0.8
coverageType = CoverageType.Branch
}
}
Note that you cannot mix multiple-checks syntax with plain check configuration:
// ok
scoverage {
check {
minimumRate = 0.5
coverageType = CoverageType.Statement
}
}
// ok
scoverage {
minimumRate = 0.2
}
// NOT ok
scoverage {
minimumRate = 0.2
check {
minimumRate = 0.5
coverageType = CoverageType.Statement
}
}
In case you use the Kotlin DSL, the following snippet can give you pointers for configuring Scoverage:
scoverage {
minimumRate.set(BigDecimal("0.80"))
excludedPackages.set(listOf<String>("com.example.scala.demo"))
}
In order for the plugin to work alongside Palantir's consistent versions plugin,
the Scala version must be manually configured (via scoverageScalaVersion
); otherwise, the plugin will attempt to
resolve the compilation classpath, which is prohibited by the versions plugin.
- Requires scoverage 2.0
- Adds support for Scala 3
- Drops support for disabling normal compilation
- Running without normal compilation is now made with
-PscoverageCompileOnly
instead of-x compileScala
.
- Requires scoverage 1.4.2 or higher (and uses this version by default)
- Adds support for Scala 2.13
- Drops support for Scala 2.11
- Requires scoverage 1.4.1 or higher (and uses this version by default)
- Requires application of the plugin to appropriate subprojects. A multi-module project might apply it to all.
plugins {
id 'org.scoverage' version '4.0.0'
}
subprojects {
apply plugin: 'org.scoverage'
}
-
No more
testScoverage
task; instead,test
will 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
scoverage
block. 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")
}