@@ -2,6 +2,7 @@ package scoverage
22
33import sbt .Keys ._
44import sbt ._
5+ import sbt .plugins .JvmPlugin
56import scoverage .report .{CoverageAggregator , CoberturaXmlWriter , ScoverageHtmlWriter , ScoverageXmlWriter }
67
78object ScoverageSbtPlugin extends AutoPlugin {
@@ -18,19 +19,15 @@ object ScoverageSbtPlugin extends AutoPlugin {
1819 val aggregateFilter = ScopeFilter (inAggregates(ThisProject ),
1920 inConfigurations(Compile )) // must be outside of the 'coverageAggregate' task (see: https://github.com/sbt/sbt/issues/1095 or https://github.com/sbt/sbt/issues/780)
2021
21- override def requires = plugins.JvmPlugin
22- override def trigger = allRequirements
22+ override def requires : JvmPlugin . type = plugins.JvmPlugin
23+ override def trigger : PluginTrigger = allRequirements
2324
2425 override lazy val projectSettings = Seq (
2526 coverageEnabled := false ,
2627 commands += Command .command(" coverage" , " enable compiled code with instrumentation" , " " )(toggleCoverage(true )),
2728 commands += Command .command(" coverageOff" , " disable compiled code with instrumentation" , " " )(toggleCoverage(false )),
2829 coverageReport <<= coverageReport0,
2930 coverageAggregate <<= coverageAggregate0,
30- libraryDependencies ++= Seq (
31- OrgScoverage % (ScalacRuntimeArtifact + " _" + scalaBinaryVersion.value) % DefaultScoverageVersion % " provided" intransitive(),
32- OrgScoverage % (ScalacPluginArtifact + " _" + scalaBinaryVersion.value) % DefaultScoverageVersion % " provided" intransitive()
33- ),
3431 scalacOptions in(Compile , compile) ++= scoverageScalacOptions.value,
3532 aggregate in coverageAggregate := false ,
3633 coverageExcludedPackages := " " ,
@@ -52,8 +49,16 @@ object ScoverageSbtPlugin extends AutoPlugin {
5249 */
5350 private def toggleCoverage (status : Boolean ): State => State = { state =>
5451 val extracted = Project .extract(state)
55- val newSettings = extracted.structure.allProjectRefs map { proj =>
56- coverageEnabled in proj := status
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+ )
5762 }
5863 extracted.append(newSettings, state)
5964 }
0 commit comments