Skip to content

Commit 0304b30

Browse files
authored
Merge pull request #168 from patrick-premont/master
Restored the ability to enable coverage with coverageEnabled
2 parents 654054b + 4510f09 commit 0304b30

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ turn it back off when you're done running reports, use the `coverageOff` command
4545

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

48+
### Disabling recording of coverage data at run-time
49+
50+
Coverage instrumentation assumes the code will be run on the same machine
51+
where it was compiled: absolute destination directories are compiled into the class files.
52+
To run the code on a file system where those directories do not exist, for example when
53+
testing in a VM, you may either recompile without coverage or disable the recording by
54+
setting the JVM property `scoverage.recording.enabled` to `false`.
55+
4856
## Notes on upgrading to version 1.3.0
4957

5058
* The object containing the keys has changed from nested to top level so you might need to adjust the import. It's also an auto plugin now, so you might not need the import at all.

src/main/scala/scoverage/ScoverageSbtPlugin.scala

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ object ScoverageSbtPlugin extends AutoPlugin {
1313
// this should match the version defined in build.sbt
1414
val DefaultScoverageVersion = "1.2.0-SNAPSHOT"
1515
val autoImport = ScoverageKeys
16+
lazy val ScoveragePluginConfig = config("scoveragePlugin").hide
1617

1718
import autoImport._
1819

@@ -28,6 +29,13 @@ object ScoverageSbtPlugin extends AutoPlugin {
2829
commands += Command.command("coverageOff", "disable compiled code with instrumentation", "")(toggleCoverage(false)),
2930
coverageReport <<= coverageReport0,
3031
coverageAggregate <<= coverageAggregate0,
32+
ivyConfigurations := ivyConfigurations.value :+ ScoveragePluginConfig,
33+
libraryDependencies ++= {
34+
if (coverageEnabled.value) Seq(
35+
OrgScoverage % (ScalacRuntimeArtifact + "_" + scalaBinaryVersion.value) % DefaultScoverageVersion,
36+
OrgScoverage % (ScalacPluginArtifact + "_" + scalaBinaryVersion.value) % DefaultScoverageVersion % "scoveragePlugin->default(compile)"
37+
) else Nil
38+
},
3139
scalacOptions in(Compile, compile) ++= scoverageScalacOptions.value,
3240
aggregate in coverageAggregate := false,
3341
coverageExcludedPackages := "",
@@ -49,17 +57,8 @@ object ScoverageSbtPlugin extends AutoPlugin {
4957
*/
5058
private def toggleCoverage(status: Boolean): State => State = { state =>
5159
val extracted = Project.extract(state)
52-
val newSettings = extracted.structure.allProjectRefs flatMap { proj =>
53-
Seq(
54-
coverageEnabled in proj := status,
55-
libraryDependencies in proj ++= {
56-
if (status) Seq(
57-
OrgScoverage % (ScalacRuntimeArtifact + "_" + scalaBinaryVersion.value) % DefaultScoverageVersion % "provided" intransitive(),
58-
OrgScoverage % (ScalacPluginArtifact + "_" + scalaBinaryVersion.value) % DefaultScoverageVersion % "provided" intransitive()
59-
) else Nil
60-
}
61-
)
62-
}
60+
val newSettings = extracted.structure.allProjectRefs.flatMap(proj =>
61+
Seq(coverageEnabled in proj := status))
6362
extracted.append(newSettings, state)
6463
}
6564

@@ -118,17 +117,16 @@ object ScoverageSbtPlugin extends AutoPlugin {
118117
}
119118

120119
private lazy val scoverageScalacOptions = Def.task {
121-
val scoverageDeps: Seq[File] = update.value matching configurationFilter("provided")
122-
scoverageDeps.find(_.getAbsolutePath.contains(ScalacPluginArtifact)) match {
123-
case None => throw new Exception(s"Fatal: $ScalacPluginArtifact not in libraryDependencies")
124-
case Some(pluginPath) =>
120+
update.value
121+
.matching(configurationFilter(ScoveragePluginConfig.name))
122+
.find(_.getAbsolutePath.contains(ScalacPluginArtifact))
123+
.fold[Seq[String]](Nil)(pluginPath =>
125124
scalaArgs(coverageEnabled.value,
126125
pluginPath,
127126
crossTarget.value,
128127
coverageExcludedPackages.value,
129128
coverageExcludedFiles.value,
130-
coverageHighlighting.value)
131-
}
129+
coverageHighlighting.value))
132130
}
133131

134132
private def scalaArgs(coverageEnabled: Boolean,

0 commit comments

Comments
 (0)