- Notifications
You must be signed in to change notification settings - Fork46
scoverage/scoverage-maven-plugin
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
scoverage-maven-plugin is a plugin for Maven that integrates the scoverage code coverage library. Find out more aboutscoverage.
mostly used mojos:
check goal compiles classes with instrumentation, runs unit tests and checks coverage,
report goal compiles classes with instrumentation, runs unit tests and generates reports,
integration-check goal compiles classes with instrumentation, runs unit and integration tests and checks coverage,
integration-report goal compiles classes with instrumentation, runs unit and integration tests and generates reports,
additional, sometimes useful, mojos:
test goal compiles classes with instrumentation and runs unit tests,
integration-test goal compiles classes with instrumentation and runs unit and integration tests,
check-only goal only checks coverage using coverage data generated earlier in the build (bytest,report,integration-test orintegration-report goal).
report-only goal generates reports using coverage data generated earlier in the build (bytest,check,integration-test orintegration-check goal),
package goal generates artifact file containing instrumented classes (e.g. for testing outside of the Maven build),
internal mojos:
- pre-compile andpost-compile are internal goals, they configure Maven build in forked
scoveragelife cycle; don't use them.
| Version | Documentation |
|---|---|
2.1.3 | Plugin Info |
1.4.11 | Plugin Info |
- The plugin is compatible withScala Maven Plugin
- version
3.0.0or later required - addScalacArgs andanalysisCacheFile configuration parameters cannot be set directly, use project properties
addScalacArgsandanalysisCacheFileinstead.
- version
- Starting with version
2.1.0JDK17+, Maven3.6.3andmaven-site-plugin3.20.0+are required. - Starting with version
2.0.0the plugin supports Scala2.12.8+,2.13.0+and3.2.0+. For Scala2.12.7and lower please use version1.4.11of the plugin. - The plugin is not thread-safe, so it should not be used in multi-threaded builds.
This can be set as project property.
<project> <properties> <scoverage.plugin.version>2.1.3</scoverage.plugin.version> </properties></project>
The plugin automatically loads and configures matchingscalac-scoverage-plugin artifact when needed.For this to work the Scala version has to be set. It can be done by defining thescalaVersion plugin configuration parameter or thescala.version project property.Without this setting, the plugin will try to resolve the Scala version from thescala-library dependency of the project.If all the attempts to resolve the Scala version fail, then coverage will not be calculated.
<project> <properties> <scala.version>2.13.18</scala.version> </properties></project>
or
<project> <build> <plugins> <plugin> <groupId>org.scoverage</groupId> <artifactId>scoverage-maven-plugin</artifactId> <version>${scoverage.plugin.version}</version> <configuration> <scalaVersion>2.13.18</scalaVersion><!-- other parameters--> </configuration> </plugin> </plugins> </build></project>
The first method is better because once the property is defined its value can be used in other places of the build file.For example in thescala-library dependency version every Scala build should declare.
<project> <dependencies> <dependency> <groupId>org.scala-lang</groupId> <artifactId>scala-library</artifactId> <version>${scala.version}</version> </dependency> </dependencies></project>
Maven SCoverage plugin uses by default the latest version of thescalac-scoverage-plugin available on its release day.If newer, better version ofscalac-scoverage-plugin is available, it can be used instead.It can be configured by defining thescalacPluginVersion plugin configuration parameter or thescoverage.scalacPluginVersion project property.
<project> <properties> <scoverage.scalacPluginVersion>2.4.2</scoverage.scalacPluginVersion> </properties></project>
or
<project> <build> <plugins> <plugin> <groupId>org.scoverage</groupId> <artifactId>scoverage-maven-plugin</artifactId> <version>${scoverage.plugin.version}</version> <configuration> <scalacPluginVersion>2.4.2</scalacPluginVersion><!-- other parameters--> </configuration> </plugin> </plugins> </build></project>
integration-check andintegration-report mojos are similar tocheck andreport mojos, but they execute forkedscoverage life cycle up toverify phase (integration tests are usually executed inintegration-test phase).
There is no separate mojo for aggregated reports, there isaggregate parameter.To additionally generate aggregated SCoverage report for root module, when generating regular reports,setaggregate parameter value totrue.It works only in multimodule projects, the aggregated report will be generated in the currentexecution root.
It can be configured by defining theaggregate plugin configuration parameter or thescoverage.aggregate project property.
<project> <properties> <scoverage.aggregate>true</scoverage.aggregate> </properties></project>
inbuild/plugins orbuild/pluginManagement section when running reports directly from console (e.g.mvn scoverage:report)
<project> <build> <plugins> <plugin> <groupId>org.scoverage</groupId> <artifactId>scoverage-maven-plugin</artifactId> <version>${scoverage.plugin.version}</version> <configuration> <aggregate>true</aggregate> </configuration> </plugin> </plugins> </build></project>
or inreporting/plugins section when adding report to Maven generated site
<project> <reporting> <plugins> <plugin> <groupId>org.scoverage</groupId> <artifactId>scoverage-maven-plugin</artifactId> <version>${scoverage.plugin.version}</version> <configuration> <aggregate>true</aggregate> </configuration> </plugin> </plugins> </reporting></project>
Since version1.4.0-M5 it's possible to generate aggregated report only, without generating reports for individual modules. For large projects it can decrease build time significantly.
To generate only aggregated SCoverage report, setaggregateOnly parameter value totrue. It works only in multimodule projects.
It can be configured by defining theaggregateOnly plugin configuration parameter or thescoverage.aggregateOnly project property.
<project> <properties> <scoverage.aggregateOnly>true</scoverage.aggregateOnly> </properties></project>
inbuild/plugins orbuild/pluginManagement section when running reports directly from console (e.g.mvn scoverage:report)
<project> <build> <plugins> <plugin> <groupId>org.scoverage</groupId> <artifactId>scoverage-maven-plugin</artifactId> <version>${scoverage.plugin.version}</version> <configuration> <aggregateOnly>true</aggregateOnly> </configuration> </plugin> </plugins> </build></project>
or inreporting/plugins section when adding report to Maven generated site
<project> <reporting> <plugins> <plugin> <groupId>org.scoverage</groupId> <artifactId>scoverage-maven-plugin</artifactId> <version>${scoverage.plugin.version}</version> <configuration> <aggregateOnly>true</aggregateOnly> </configuration> </plugin> </plugins> </reporting></project>
Add the plugin to reporting section of your project and configure it to generate one of reporting mojos.By default, Maven executes all plugin's reporting mojos, but the SCoverage plugin has three such mojos,and it does not make sense to execute them all because every executed report will overwrite the previous one.Configure one of them depending on your case.
<project> <reporting> <plugins> <plugin> <groupId>org.scoverage</groupId> <artifactId>scoverage-maven-plugin</artifactId> <version>${scoverage.plugin.version}</version> <reportSets> <reportSet> <reports> <report>report</report><!-- or <report>integration-report</report>--><!-- or <report>report-only</report>--> </reports> </reportSet> </reportSets> </plugin> </plugins> </reporting></project>
Which reporting mojo should be selected:
| Reporting mojo | When |
|---|---|
| report | When not using integration tests (most cases) |
| integration-report | When using integration tests |
| report-only | When coverage data was already generated (usually bycheck orintegration-check mojo) |
If you want to customize plugin's configuration parameters used by compilation supporting part of the plugin, do it in 'plugins' or 'pluginManagement' section:
<project> <build> <plugins> <plugin> <groupId>org.scoverage</groupId> <artifactId>scoverage-maven-plugin</artifactId> <version>${scoverage.plugin.version}</version> <configuration> <highlighting>true</highlighting><!-- example configuration for Play! Framework 2.x project--> <excludedPackages>views.html.*</excludedPackages> <excludedFiles>.*?routes_(routing|reverseRouting)</excludedFiles> </configuration> </plugin> </plugins> </build></project>
ReadSBT SCoverage Plugin documentation for more information aboutexcludedPackages and excludedFiles.
File and package exclusions are supported for Scala 2, Scala [3.3.4-3.4.0) and3.4.2+.
<project> <build> <plugins> <plugin> <groupId>org.scoverage</groupId> <artifactId>scoverage-maven-plugin</artifactId> <version>${scoverage.plugin.version}</version> <configuration> <minimumCoverage>95</minimumCoverage> <minimumCoverageBranchTotal>90</minimumCoverageBranchTotal> <minimumCoverageStmtPerPackage>90</minimumCoverageStmtPerPackage> <minimumCoverageBranchPerPackage>85</minimumCoverageBranchPerPackage> <minimumCoverageStmtPerFile>85</minimumCoverageStmtPerFile> <minimumCoverageBranchPerFile>80</minimumCoverageBranchPerFile> <failOnMinimumCoverage>true</failOnMinimumCoverage> </configuration> <executions> <execution> <goals> <goal>check</goal><!-- or integration-check--> </goals> </execution> </executions> </plugin> </plugins> </build></project>
Runmvn scoverage:check to perform the check. See below if you want to usemvn verify to perform the check.
ReadSBT SCoverage Plugin documentation for more information.
<project> <build> <plugins> <plugin> <groupId>org.scoverage</groupId> <artifactId>scoverage-maven-plugin</artifactId> <version>${scoverage.plugin.version}</version> <configuration> <minimumCoverage>80</minimumCoverage> <failOnMinimumCoverage>true</failOnMinimumCoverage> </configuration> <executions> <execution> <goals> <goal>check</goal><!-- or integration-check--> </goals> </execution> </executions> </plugin> </plugins> </build> <reporting> <plugins> <plugin> <groupId>org.scoverage</groupId> <artifactId>scoverage-maven-plugin</artifactId> <version>${scoverage.plugin.version}</version> <reportSets> <reportSet> <reports> <report>report-only</report> </reports> </reportSet> </reportSets> </plugin> </plugins> </reporting></project>
Runmvn scoverage:check to perform the check andmvn scoverage:report to generate the report.
If you wantmvn verify andmvn install to check the coverage level, you have to change your POMso that SCoverage takes over running all the tests.
The reason for this is that SCoverage instruments classes during compilation and writes them to disk.We don't want to accidentally deploy these instrumented classes, so SCoverage keeps them separate.SCoverage does this by forking the current Maven build and running it again, while performing instrumentation.In a normal setup this causes the tests to be run twice: once in the outer run with the original classesand once in the SCoverage-forked run with the instrumented classes.
Since version1.4.0-M5 it's possible to make the tests run only once. You have to configure your pom to turn off testing in the outer run and tell SCoverage to run all tests in the forked run.
This example shows the required configuration:
<project> <properties> <skipTests>true</skipTests><!-- disable surefire and failsafe tests--> </properties>... <build> <plugins> <plugin> <groupId>org.scoverage</groupId> <artifactId>scoverage-maven-plugin</artifactId> <version>${scoverage.plugin.version}</version> <configuration> <minimumCoverage>80</minimumCoverage> <failOnMinimumCoverage>true</failOnMinimumCoverage><!-- enable surefire and failsafe tests in SCoverage--> <additionalForkedProjectProperties>skipTests=false</additionalForkedProjectProperties> </configuration> <executions> <execution> <goals> <goal>check</goal><!-- or integration-check--> </goals> <phase>prepare-package</phase><!-- or any other phase--> </execution> </executions> </plugin> </plugins> </build></project>
Runmvn clean verify ormvn clean install to run the tests with coverage and all other static analysis you have configured.
If you want to set multiple properties from within<additionalForkedProjectProperties>, for instance because you want to disable other plugins from running twice, you can separate them with a semicolon:
<additionalForkedProjectProperties>skipTests=false;skip.scalafmt=false</additionalForkedProjectProperties>
There are many example projects inintegration tests directory. To run them, executemvn integration-test.To execute only one of them, executemvn integration-test -Dinvoker.test=test_aggregate, wheretest_aggregate is the name of the directory with the example project.
Also, there are manyexample projects for older versions of the plugin in a separate repo.Go to one of them and runmvn site.
A new snapshot is deployed to sonatype on each commit merged tomain branch. Seesnapshot.yml workflow for details.
A new release can be done on demand usingRelease new version workflow. Seerelease.yml for details.
- Run
Release new versionworkflow. - Wait ~ 8 hours for sync to maven central.
- Check jars are available in maven centralhttps://search.maven.org/artifact/org.scoverage/scoverage-maven-plugin and GH label in README is updated.
- Checkout new tag, e.g.
git checkout scoverage-maven-plugin-2.1.3. - Generate site docs with
mvn clean site -P publicsiteand check that all required docs are generated in./target/site. - Checkout
gh-pagesbranch, e.g.git checkout gh-pages. - Copy generated site to new directory named as version number, e.g.
cp -r ./target/site ./2.1.3, commit and push. - Wait several seconds for the docs to be published and verify, e.g.https://scoverage.github.io/scoverage-maven-plugin/2.1.3/check-mojo.html.
- Checkout
mainbranch, e.g.git checkout main. - Update versions in README, e.g.
sed -i 's/2.1.2/2.1.3/g' README.md, commit and push. - Create new Release on GitHub.
This process will be fully or partially automated in the future.
Set sonatype credentials in~/.m2/settings.xml:
<settings> <servers> <server> <id>central</id> <username>sonatype-username-goes-here</username> <password>sonatype-token-goes-here</password> </server> </servers></settings>
Make sure you have proper pgp keys set up. SeeMaven Central Guide for details.
- Run
mvn -ntp -B release:clean release:prepare release:perform -P release -Darguments="-DskipTests". - Follow steps 2-11 above
This software is licensed under the Apache 2 license, quoted below.Copyright 2014-2025 Grzegorz SlowikowskiLicensed under the Apache License, Version 2.0 (the "License"); you may notuse this file except in compliance with the License. You may obtain a copy ofthe License at http://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS, WITHOUTWARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See theLicense for the specific language governing permissions and limitations underthe License.About
Maven plugin for scoverage
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.