正如您所注意到的,似乎编写覆盖范围的方式强制将此依赖项添加到编译中的 libraryDependencies 中。然而,一种解决方法是使用 sbt 中的 makePomConfiguration 设置。您可以对构建的 POM 执行转换以删除添加的依赖项,而不会影响覆盖的工作方式。下面我做了一个构建,它将过滤掉你的 POM 中的覆盖依赖。我使用了 .scala 文件,因为您无法在 build.sbt pre 0.13 中定义对象。所以这个文件将位于 project/Build.scala。
import sbt.Keys._
import sbt._
import scala.xml.{Elem, Node}
import scala.xml.transform.{RuleTransformer, RewriteRule}
object theBuild extends Build {
object FilterBadDependency extends RewriteRule {
override def transform(n: Node): Seq[Node] = n match {
/**
* When we find the dependencies node we want to rewrite it removing any of
* the scoverage dependencies.
*/
case dependencies @ Elem(_, "dependencies", _, _, _*) =>
<dependencies>
{
dependencies.child filter { dep =>
(dep \ "groupId").text != "com.sksamuel.scoverage"
}
}
</dependencies>
/**
* Otherwise we just skip over the node and do nothing
*/
case other => other
}
}
object TransformFilterBadDependencies extends RuleTransformer(FilterBadDependency)
val project = Project(
id = "test-build",
base = file(".")
).settings(
ScoverageSbtPlugin.instrumentSettings: _*
).settings(
/**
* Here we alter our make pom configuration so that our transformation is applied to
* the constructed pom
*/
makePomConfiguration ~= { config =>
config.copy(process = TransformFilterBadDependencies)
})
}