@@ -2,6 +2,7 @@ package scoverage
2
2
3
3
import sbt .Keys ._
4
4
import sbt ._
5
+ import sbt .plugins .JvmPlugin
5
6
import scoverage .report .{CoverageAggregator , CoberturaXmlWriter , ScoverageHtmlWriter , ScoverageXmlWriter }
6
7
7
8
object ScoverageSbtPlugin extends AutoPlugin {
@@ -18,19 +19,15 @@ object ScoverageSbtPlugin extends AutoPlugin {
18
19
val aggregateFilter = ScopeFilter (inAggregates(ThisProject ),
19
20
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)
20
21
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
23
24
24
25
override lazy val projectSettings = Seq (
25
26
coverageEnabled := false ,
26
27
commands += Command .command(" coverage" , " enable compiled code with instrumentation" , " " )(toggleCoverage(true )),
27
28
commands += Command .command(" coverageOff" , " disable compiled code with instrumentation" , " " )(toggleCoverage(false )),
28
29
coverageReport <<= coverageReport0,
29
30
coverageAggregate <<= coverageAggregate0,
30
- libraryDependencies ++= Seq (
31
- OrgScoverage % (ScalacRuntimeArtifact + " _" + scalaBinaryVersion.value) % DefaultScoverageVersion % " provided" intransitive(),
32
- OrgScoverage % (ScalacPluginArtifact + " _" + scalaBinaryVersion.value) % DefaultScoverageVersion % " provided" intransitive()
33
- ),
34
31
scalacOptions in(Compile , compile) ++= scoverageScalacOptions.value,
35
32
aggregate in coverageAggregate := false ,
36
33
coverageExcludedPackages := " " ,
@@ -52,8 +49,16 @@ object ScoverageSbtPlugin extends AutoPlugin {
52
49
*/
53
50
private def toggleCoverage (status : Boolean ): State => State = { state =>
54
51
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
+ )
57
62
}
58
63
extracted.append(newSettings, state)
59
64
}
0 commit comments