Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
{ version: '2.12.12' },
{ version: '2.12.11' },
{ version: '2.12.10' },
{ version: '2.13.5' },
{ version: '2.13.4' },
{ version: '2.13.3' },
{ version: '2.13.2' },
Expand Down
20 changes: 6 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,12 @@ discussion on scoverage.

Make sure your SBT version in project/build.properties:
```
sbt.version = 0.13.17
```
or
```
sbt.version = 1.1.1
sbt.version = 1.5.1
```

Add the plugin in project/plugins.sbt:
```scala
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.1")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.2")
```

Run the tests with enabled coverage:
Expand Down Expand Up @@ -54,6 +50,10 @@ turn it back off when you're done running reports, use the `coverageOff` command

Sample project with scoverage in both sbt and maven - [the scoverage samples project](https://github.com/scoverage/sbt-scoverage-samples).

## Notes on upgrading to version 1.6.x
* ´coverageCleanSubprojectFiles´ key has been removed
* scala version 2.12+ is required as a minimum

## Notes on upgrading to version 1.6.0

* `coverageAggregate` aggregates raw coverage data, not coverage xml reports for modules.
Expand Down Expand Up @@ -117,14 +117,6 @@ coverageFailOnMinimum := true
These settings will be enforced when the reports are generated.
If you generate an aggregate report using `coverageAggregate` then these settings will apply to that report.

## Highlighting

If you are using Scala 2.11.1 or less, then highlighting will not work (due to this bug which was fixed in 2.11.2 https://github.com/scala/scala/pull/3799). In that case you must disable highlighting by adding the following to your build:

```scala
coverageHighlighting := false
```

## Failing tests
Scoverage does a lot of file writing behind the scenes in order to track which statements have been executed.
If you are running into a scenario where your tests normally pass, but fail when scoverage is enabled, then the culprit can be one of the following:
Expand Down
118 changes: 60 additions & 58 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,77 +1,79 @@
name := "sbt-scoverage"

organization := "org.scoverage"

enablePlugins(SbtPlugin)

scalacOptions := Seq("-unchecked", "-deprecation", "-feature", "-encoding", "utf8")

resolvers ++= {
if (isSnapshot.value) Seq(Resolver.sonatypeRepo("snapshots")) else Nil
}

libraryDependencies += "org.scoverage" %% "scalac-scoverage-plugin" % "1.4.0"

publishMavenStyle := true

publishArtifact in Test := false
import sbt.ScriptedPlugin.autoImport.scriptedLaunchOpts
import sbtrelease.ReleasePlugin.autoImport.ReleaseTransformations._

scriptedLaunchOpts ++= Seq(
"-Xmx1024M",
"-Dplugin.version=" + version.value
)

import ReleaseTransformations._
releaseProcess := Seq[ReleaseStep](
checkSnapshotDependencies,
inquireVersions,
runClean,
releaseStepCommandAndRemaining("^ test"),
// releaseStepCommandAndRemaining("^ scripted"),
setReleaseVersion,
commitReleaseVersion,
tagRelease,
releaseStepCommandAndRemaining("^ publishSigned"),
releaseStepCommandAndRemaining("^ publish"),
setNextVersion,
commitNextVersion,
pushChanges
)

releaseCrossBuild := false

publishTo := {
if (isSnapshot.value)
Some("snapshots" at "https://oss.sonatype.org/content/repositories/snapshots")
else
Some("releases" at "https://oss.sonatype.org/service/local/staging/deploy/maven2")
}

pomExtra := {
<url>https://github.com/scoverage/sbt-scoverage</url>
<licenses>
<license>
<name>Apache 2</name>
<url>http://www.apache.org/licenses/LICENSE-2.0</url>
<distribution>repo</distribution>
</license>
</licenses>
<scm>
<url>git@github.com:scoverage/sbt-scoverage.git</url>
<connection>scm:git@github.com:scoverage/sbt-scoverage.git</connection>
</scm>
<developers>
<developer>
<id>sksamuel</id>
<name>sksamuel</name>
<url>http://github.com/sksamuel</url>
</developer>
<developer>
<id>gslowikowski</id>
<name>Grzegorz Slowikowski</name>
<url>http://github.com/gslowikowski</url>
</developer>
</developers>
}

crossSbtVersions := Vector("0.13.18", "1.2.8")
lazy val root = Project("sbt-scoverage", file("."))
.enablePlugins(SbtPlugin)
.settings(
libraryDependencies ++= Seq(
"org.scala-lang" % "scala-compiler" % scalaVersion.value % Compile
),
libraryDependencies += "org.scoverage" %% "scalac-scoverage-plugin" % "1.4.3-SNAPSHOT" cross(CrossVersion.full),
scalaVersion := "2.12.13",
publishMavenStyle := true,
publishConfiguration := publishConfiguration.value.withOverwrite(true),
publishLocalConfiguration := publishLocalConfiguration.value.withOverwrite(true),
releasePublishArtifactsAction := PgpKeys.publishSigned.value,
Test / fork := false,
Test / publishArtifact := false,
Test / parallelExecution := false,
scalacOptions := Seq("-unchecked", "-deprecation", "-feature", "-encoding", "utf8"),
publishTo := {
if (isSnapshot.value)
Some("snapshots" at "https://oss.sonatype.org/content/repositories/snapshots")
else
Some("releases" at "https://oss.sonatype.org/service/local/staging/deploy/maven2")
},
resolvers ++= {
if (isSnapshot.value) Seq(Resolver.sonatypeRepo("snapshots")) else Nil
},
scriptedLaunchOpts ++= Seq(
"-Xmx1024M",
"-Dplugin.version=" + version.value
),
pomExtra := {
<url>https://github.com/scoverage/sbt-scoverage</url>
<licenses>
<license>
<name>Apache 2</name>
<url>http://www.apache.org/licenses/LICENSE-2.0</url>
<distribution>repo</distribution>
</license>
</licenses>
<scm>
<url>git@github.com:scoverage/sbt-scoverage.git</url>
<connection>scm:git@github.com:scoverage/sbt-scoverage.git</connection>
</scm>
<developers>
<developer>
<id>sksamuel</id>
<name>sksamuel</name>
<url>http://github.com/sksamuel</url>
</developer>
<developer>
<id>gslowikowski</id>
<name>Grzegorz Slowikowski</name>
<url>http://github.com/gslowikowski</url>
</developer>
</developers>
}
)

scalariformAutoformat := false
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.2.8
sbt.version=1.5.1
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.0")

addSbtPlugin("org.scalariform" % "sbt-scalariform" % "1.8.1")

addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.7")
addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.13")
2 changes: 0 additions & 2 deletions src/main/scala/scoverage/ScoverageKeys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ object ScoverageKeys {
lazy val coverageOutputXML = settingKey[Boolean]("enables xml report generation")
lazy val coverageOutputHTML = settingKey[Boolean]("enables html report generation")
lazy val coverageOutputDebug = settingKey[Boolean]("turn on the debug report")
@deprecated("", "1.6.0")
lazy val coverageCleanSubprojectFiles = settingKey[Boolean]("removes subproject data after an aggregation")
lazy val coverageOutputTeamCity = settingKey[Boolean]("turn on teamcity reporting")
lazy val coverageScalacPluginVersion = settingKey[String]("version of scalac-scoverage-plugin to use")
}
25 changes: 12 additions & 13 deletions src/main/scala/scoverage/ScoverageSbtPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ object ScoverageSbtPlugin extends AutoPlugin {
val ScalacRuntimeArtifact = "scalac-scoverage-runtime"
val ScalacPluginArtifact = "scalac-scoverage-plugin"
// this should match the version defined in build.sbt
val DefaultScoverageVersion = "1.4.1"
val DefaultScoverageVersion = "1.4.3-SNAPSHOT"
val autoImport = ScoverageKeys
lazy val ScoveragePluginConfig = config("scoveragePlugin").hide

Expand All @@ -34,40 +34,39 @@ object ScoverageSbtPlugin extends AutoPlugin {
coverageOutputHTML := true,
coverageOutputCobertura := true,
coverageOutputDebug := false,
coverageCleanSubprojectFiles := true,
coverageOutputTeamCity := false,
coverageScalacPluginVersion := DefaultScoverageVersion
)

override def buildSettings: Seq[Setting[_]] = super.buildSettings ++
addCommandAlias("coverage", ";set coverageEnabled in ThisBuild := true") ++
addCommandAlias("coverageOn", ";set coverageEnabled in ThisBuild := true") ++
addCommandAlias("coverageOff", ";set coverageEnabled in ThisBuild := false")
addCommandAlias("coverage", ";set ThisBuild / coverageEnabled := true") ++
addCommandAlias("coverageOn", ";set ThisBuild / coverageEnabled := true") ++
addCommandAlias("coverageOff", ";set ThisBuild / coverageEnabled := false")

override def projectSettings: Seq[Setting[_]] = Seq(
ivyConfigurations += ScoveragePluginConfig,
coverageReport := coverageReport0.value,
coverageAggregate := coverageAggregate0.value,
aggregate in coverageAggregate := false
coverageAggregate / aggregate := false
) ++ coverageSettings ++ scalacSettings

private lazy val coverageSettings = Seq(
libraryDependencies ++= {
if (coverageEnabled.value)
libraryDependencies ++= {
if (coverageEnabled.value) {
Seq(
// We only add for "compile" because of macros. This setting could be optimed to just "test" if the handling
// of macro coverage was improved.
(OrgScoverage %% (scalacRuntime(libraryDependencies.value)) % coverageScalacPluginVersion.value).cross(CrossVersion.full),
// We don't want to instrument the test code itself, nor add to a pom when published with coverage enabled.
(OrgScoverage %% ScalacPluginArtifact % coverageScalacPluginVersion.value % ScoveragePluginConfig.name).cross(CrossVersion.full)
)
else
} else
Nil
}
)

private lazy val scalacSettings = Seq(
scalacOptions in(Compile, compile) ++= {
Compile / compile / scalacOptions ++= {
val updateReport = update.value
if (coverageEnabled.value) {
val scoverageDeps: Seq[File] = updateReport matching configurationFilter(ScoveragePluginConfig.name)
Expand Down Expand Up @@ -113,14 +112,14 @@ object ScoverageSbtPlugin extends AutoPlugin {
case Some(cov) =>
writeReports(
target,
(sourceDirectories in Compile).value,
(Compile / sourceDirectories).value,
cov,
coverageOutputCobertura.value,
coverageOutputXML.value,
coverageOutputHTML.value,
coverageOutputDebug.value,
coverageOutputTeamCity.value,
sourceEncoding((scalacOptions in (Compile)).value),
sourceEncoding((Compile / scalacOptions).value),
log)

checkCoverage(cov, log, coverageMinimum.value, coverageFailOnMinimum.value)
Expand All @@ -144,7 +143,7 @@ object ScoverageSbtPlugin extends AutoPlugin {
coverageOutputHTML.value,
coverageOutputDebug.value,
coverageOutputTeamCity.value,
sourceEncoding((scalacOptions in (Compile)).value),
sourceEncoding((Compile / scalacOptions).value),
log)
val cfmt = cov.statementCoverageFormatted
log.info(s"Aggregation complete. Coverage was [$cfmt]")
Expand Down
6 changes: 3 additions & 3 deletions src/sbt-test/scoverage/aggregate-only/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
lazy val commonSettings = Seq(
organization := "org.scoverage",
version := "0.1.0",
scalaVersion := "2.12.8"
scalaVersion := "2.12.13"
)

lazy val specs2Lib = "org.specs2" %% "specs2" % "2.5" % "test"
Expand Down Expand Up @@ -34,7 +34,7 @@ lazy val root = (project in file("."))
partB
)

resolvers in ThisBuild ++= {
if (sys.props.get("plugin.version").map(_.endsWith("-SNAPSHOT")).getOrElse(false)) Seq(Resolver.sonatypeRepo("snapshots"))
ThisBuild / resolvers ++= {
if (sys.props.get("plugin.version").exists(_.endsWith("-SNAPSHOT"))) Seq(Resolver.sonatypeRepo("snapshots"))
else Seq.empty
}
2 changes: 1 addition & 1 deletion src/sbt-test/scoverage/aggregate-only/project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ val pluginVersion = sys.props.getOrElse(
"""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin))

addSbtPlugin("org.scoverage" % "sbt-scoverage" % pluginVersion)
addSbtPlugin("org.scoverage" % "sbt-scoverage" % pluginVersion withCrossVersion(CrossVersion.full))

resolvers ++= {
if (pluginVersion.endsWith("-SNAPSHOT"))
Expand Down
6 changes: 3 additions & 3 deletions src/sbt-test/scoverage/aggregate/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
lazy val commonSettings = Seq(
organization := "org.scoverage",
version := "0.1.0",
scalaVersion := "2.12.8"
scalaVersion := "2.12.13"
)

lazy val specs2Lib = "org.specs2" %% "specs2" % "2.5" % "test"
Expand Down Expand Up @@ -34,7 +34,7 @@ lazy val root = (project in file("."))
partB
)

resolvers in ThisBuild ++= {
if (sys.props.get("plugin.version").map(_.endsWith("-SNAPSHOT")).getOrElse(false)) Seq(Resolver.sonatypeRepo("snapshots"))
ThisBuild / resolvers ++= {
if (sys.props.get("plugin.version").exists(_.endsWith("-SNAPSHOT"))) Seq(Resolver.sonatypeRepo("snapshots"))
else Seq.empty
}
2 changes: 1 addition & 1 deletion src/sbt-test/scoverage/aggregate/project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ val pluginVersion = sys.props.getOrElse(
"""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin))

addSbtPlugin("org.scoverage" % "sbt-scoverage" % pluginVersion)
addSbtPlugin("org.scoverage" % "sbt-scoverage" % pluginVersion withCrossVersion(CrossVersion.full))

resolvers ++= {
if (pluginVersion.endsWith("-SNAPSHOT"))
Expand Down
4 changes: 2 additions & 2 deletions src/sbt-test/scoverage/bad-coverage/build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version := "0.1"

scalaVersion := "2.12.8"
scalaVersion := "2.12.13"

libraryDependencies += "org.specs2" %% "specs2" % "2.5" % "test"

Expand All @@ -9,6 +9,6 @@ coverageMinimum := 80
coverageFailOnMinimum := true

resolvers ++= {
if (sys.props.get("plugin.version").map(_.endsWith("-SNAPSHOT")).getOrElse(false)) Seq(Resolver.sonatypeRepo("snapshots"))
if (sys.props.get("plugin.version").exists(_.endsWith("-SNAPSHOT"))) Seq(Resolver.sonatypeRepo("snapshots"))
else Seq.empty
}
2 changes: 1 addition & 1 deletion src/sbt-test/scoverage/bad-coverage/project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ val pluginVersion = sys.props.getOrElse(
"""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin))

addSbtPlugin("org.scoverage" % "sbt-scoverage" % pluginVersion)
addSbtPlugin("org.scoverage" % "sbt-scoverage" % pluginVersion withCrossVersion(CrossVersion.full))

resolvers ++= {
if (pluginVersion.endsWith("-SNAPSHOT"))
Expand Down
4 changes: 2 additions & 2 deletions src/sbt-test/scoverage/coverage-off/build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version := "0.1"

scalaVersion := "2.12.8"
scalaVersion := "2.12.13"

libraryDependencies += "org.specs2" %% "specs2" % "2.5" % "test"

Expand All @@ -9,6 +9,6 @@ coverageMinimum := 80
coverageFailOnMinimum := true

resolvers ++= {
if (sys.props.get("plugin.version").map(_.endsWith("-SNAPSHOT")).getOrElse(false)) Seq(Resolver.sonatypeRepo("snapshots"))
if (sys.props.get("plugin.version").exists(_.endsWith("-SNAPSHOT"))) Seq(Resolver.sonatypeRepo("snapshots"))
else Seq.empty
}
2 changes: 1 addition & 1 deletion src/sbt-test/scoverage/coverage-off/project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ val pluginVersion = sys.props.getOrElse(
"""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin))

addSbtPlugin("org.scoverage" % "sbt-scoverage" % pluginVersion)
addSbtPlugin("org.scoverage" % "sbt-scoverage" % pluginVersion withCrossVersion(CrossVersion.full))

resolvers ++= {
if (pluginVersion.endsWith("-SNAPSHOT"))
Expand Down
Loading