Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A plugin to enable the use of Scoverage in a gradle Scala project

License

NotificationsYou must be signed in to change notification settings

scoverage/gradle-scoverage

Repository files navigation

Java CI with Gradle

gradle-scoverage

A plugin to enable the use of Scoverage in a gradle Scala project.

Usage

You can find instructions on how to apply the plugin athttp://plugins.gradle.org/plugin/org.scoverage

Available tasks

  1. reportScoverage: Produces XML and HTML reports for analysing test code coverage.

    The plugin automatically creates areport{Task name}Scoverage task for each test task in yourGradle build. ThereportScoverage task 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.

  2. aggregateScoverage: Aggregates coverage statistics in composite builds.

    When applied on a project with sub-projects, the plugin will create the aggregation taskaggregateScoverage, 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 usereportScoverage in order to generate a report without aggregation.

  3. 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, seethe relevant issue.

Configuration

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-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 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.

Multiple check tasks

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"))}

Compatibility with Consistent Versions Plugin

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.

Migration to 8.x

  • Requires scoverage 2.0
  • Adds support for Scala 3
  • Drops support for disabling normal compilation

Migration to 7.x

  • Running without normal compilation is now made with-PscoverageCompileOnly instead of-x compileScala.

Migration to 5.x

  • 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

Migration to 4.x

  • 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'}

Migration to 3.x

  • No moretestScoverage 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 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 inscoverage block. 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

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp