### Override Coverage Data Directory in sbt Build Source: https://github.com/scoverage/sbt-scoverage/blob/main/README.md Change the default location for coverage data and reports by setting `coverageDataDir` in your sbt build configuration. This allows custom output paths for scoverage artifacts, useful for specific testing setups. ```Scala coverageDataDir := target.value / "custom-test" ``` -------------------------------- ### Generate Scoverage Reports Source: https://github.com/scoverage/sbt-scoverage/blob/main/README.md After running tests with coverage, use this command to generate the HTML and XML coverage reports. Reports are saved in your `target/scala-/scoverage-report` directory, providing detailed insights into code coverage. ```sbt sbt coverageReport ``` -------------------------------- ### Run Tests with Coverage Enabled Source: https://github.com/scoverage/sbt-scoverage/blob/main/README.md Execute your project's tests with code coverage enabled. The `coverage` command instruments your code before running tests. Use `it:test` to include integration tests in the coverage run. ```sbt sbt clean coverage test ``` ```sbt sbt clean coverage it:test ``` -------------------------------- ### Add sbt-scoverage Plugin to project/plugins.sbt Source: https://github.com/scoverage/sbt-scoverage/blob/main/README.md To include the sbt-scoverage plugin in your project, add this line to your `project/plugins.sbt` file. This is the standard way to declare sbt plugins for your build. ```Scala addSbtPlugin("org.scoverage" % "sbt-scoverage" % "x.x.x") ``` -------------------------------- ### Configure Minimum Coverage Thresholds Source: https://github.com/scoverage/sbt-scoverage/blob/main/README.md Set minimum coverage percentages for statements and branches at total, package, and file levels. If these thresholds are not met, the build will fail when reports are generated. These settings apply to aggregated reports as well. ```Scala coverageFailOnMinimum := true\ncoverageMinimumStmtTotal := 90\ncoverageMinimumBranchTotal := 90\ncoverageMinimumBranchPerPackage := 85\ncoverageMinimumStmtPerFile := 85\ncoverageMinimumBranchPerFile := 80\ncoverageMinimumStmtPerPackage := 90 ``` -------------------------------- ### Aggregate Multi-Project Coverage Reports Source: https://github.com/scoverage/sbt-scoverage/blob/main/README.md For multi-project builds, use `coverageAggregate` to combine coverage data from all sub-projects into a single, aggregated report. This command processes coverage data directly, without needing prior `coverageReport` execution on sub-projects. ```sbt sbt coverageAggregate ``` -------------------------------- ### Enable Coverage in sbt Build Settings Source: https://github.com/scoverage/sbt-scoverage/blob/main/README.md To permanently enable code coverage for your project, set `coverageEnabled` to `true` in your sbt build configuration. This ensures coverage is active for subsequent commands without needing to specify `coverage` explicitly. ```Scala coverageEnabled := true ``` -------------------------------- ### Override Coverage Data Directory via sbt Set Directive Source: https://github.com/scoverage/sbt-scoverage/blob/main/README.md Alternatively, you can set the `coverageDataDir` directly from the sbt console using the `set` directive. This provides a temporary or interactive way to change the output path for coverage data. ```sbt set coverageDataDir := file("/tmp") ``` -------------------------------- ### Add sbt-scoverage Plugin as Library Dependency (Enterprise) Source: https://github.com/scoverage/sbt-scoverage/blob/main/README.md For enterprise environments where the standard plugin declaration might not work, add sbt-scoverage as a direct library dependency. This approach ensures the plugin is available for your project's dependencies. ```Scala libraryDependencies += "org.scoverage" % "sbt-scoverage_2.12_1.0" % "x.x.x" ``` -------------------------------- ### Exclude Files from Coverage Measurement Source: https://github.com/scoverage/sbt-scoverage/blob/main/README.md Specify regular expressions to exclude files or file paths from coverage. The `.scala` file extension needs to be omitted from the filename. This option only works for Scala 2, Scala 3.3.4+, and Scala 3.4.2+. ```Scala coverageExcludedFiles := ".*\\/two\\/GoodCoverage;.*\\/three\\/.*" ``` -------------------------------- ### Exclude Classes from Coverage Measurement Source: https://github.com/scoverage/sbt-scoverage/blob/main/README.md Define a semicolon-separated list of regular expressions to exclude specific classes from coverage instrumentation and reporting. The regex must match the fully qualified class name entirely. Any matched classes will not be instrumented or included in the coverage report. ```Scala coverageExcludedPackages := ";Reverse.*;.*AuthService.*;models\\.data\\..*" ``` -------------------------------- ### Exclude Code Sections Using Comments Source: https://github.com/scoverage/sbt-scoverage/blob/main/README.md Mark specific blocks of code with `// $COVERAGE-OFF$` and `// $COVERAGE-ON$` comments to prevent them from being instrumented or included in coverage reports. Any code between these comments will be excluded. This feature is only supported for Scala 2. ```Scala // $COVERAGE-OFF$Disabling highlighting by default until a workaround for https://issues.scala-lang.org/browse/SI-8596 is found\n ...\n // $COVERAGE-ON$ ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.