- Notifications
You must be signed in to change notification settings - Fork48
A plugin to enable the use of Scoverage in a gradle Scala project
License
scoverage/gradle-scoverage
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
A plugin to enable the use of Scoverage in a gradle Scala project.
You can find instructions on how to apply the plugin athttp://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}Scoveragetask for each test task in yourGradle build. ThereportScoveragetask will run all test tasks and you can use the individualtasks to run only the desired tests. For example, to run only the unit tests and no other testtasks (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, whichwill first generate reports for each project individually (including the parent project), and will then generate anaggregated 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 aprojectdoes 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
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.
Note: The plugin is not compatible with composite builds. For more information, seethe relevant issue.
The plugin exposes multiple options that can be configured by setting them in anscoverage block within the project'sbuild script. These options are as follows:
scoverageVersion = <String>(default"2.1.1): The version of the scoverage scalac plugin. This (gradle) pluginshould be compatible with all 1+ versions.scoverageScalaVersion = <String>(defaultdetected): The scala version of the scoverage scalac plugin. Thisoverrides 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 = <CoverageType.Statement | CoverageType.Branch | CoverageType.Line>(defaultCoverageType.Statement): The type of coverage validated by thecheckScoveragetask. For more information on the different types, please refer to the documentation of the scalacplugin (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:
// okscoverage { check { minimumRate = 0.5 coverageType = CoverageType.Statement }}// okscoverage { minimumRate = 0.2}// NOT okscoverage { 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 alongsidePalantir's consistent versions plugin,the Scala version must be manually configured (viascoverageScalaVersion); otherwise, the plugin will attempt toresolve 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
-PscoverageCompileOnlyinstead 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 { applyplugin:'org.scoverage'}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 scriptsdependencies { scoveragegroup:'org.scoverage',name:'scalac-scoverage-plugin_2.12',version:'1.3.1' scoveragegroup:'org.scoverage',name:'scalac-scoverage-runtime_2.12',version:'1.3.1'}
- All configurations are configured in
scoverageblock. For instance:
// do thisscoverage { minimumRate=0.5}// instead of thischeckScoverage { minimumRate=0.5}
- No more need to declare aggregation task:
// can safely delete this from build scriptstask aggregateScoverage(type:org.scoverage.ScoverageAggregate)checkScoverage { reportDir= file("$buildDir/scoverage-aggregate")}
About
A plugin to enable the use of Scoverage in a gradle Scala project
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.