scala 有没有一种简单的方法可以在 SBT 中指定全局依赖排除
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25747900/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there a simple way to specify a global dependency exclude in SBT
提问by reikje
How would you exclude a transitive dependency globally? My project depends on a lot of the Twitter libraries or on libraries that depend on the Twitter libraries. I don't want slf4j-jdk14in my classpath, no matter what (I use logback as slf4j binding).
您将如何在全局范围内排除传递依赖?我的项目依赖于很多 Twitter 库或依赖于 Twitter 库的库。我不想slf4j-jdk14在我的类路径中,无论如何(我使用 logback 作为 slf4j 绑定)。
Currently I do this:
目前我这样做:
"com.twitter" %% "finagle-thriftmux" % "6.16.0" exclude("org.slf4j", "slf4j-jdk14")
but every time someone adds another dependency that uses slf4j-jdk14I might get it back into the classpath.
但是每次有人添加另一个使用的依赖项时,slf4j-jdk14我可能会将它重新放入类路径中。
回答by Daniel Olszewski
Since sbt 0.13.8
自 sbt 0.13.8
In sbt 0.13.8 there is possibilityto exclude dependencies globally. Here is a compact example:
在 sbt 0.13.8 中,有可能全局排除依赖项。这是一个紧凑的示例:
excludeDependencies += "org.slf4j.slf4j-jdk14"
However, at the moment of writing this feature was marked as experimental so it's wise to be aware of older solution.
但是,在撰写此功能时,此功能已标记为实验性,因此了解较旧的解决方案是明智之举。
Before sbt 0.13.8
sbt 0.13.8 之前
For a group of dependencies you can do it as follows:
对于一组依赖项,您可以按如下方式进行:
libraryDependencies ++= Seq(
"com.twitter" %% "finagle-thriftmux" % "6.16.0",
"com.twitter" % "lib" % "2.0",
"com.domain" % "some-other-lib" % "1.0"
).map(_.exclude("org.slf4j", "slf4j-jdk14"))
回答by Jeffrey Aguilera
excludeDependencies += "org.slf4j" % "slf4j-jdk14"
excludeDependencies += "org.slf4j" % "slf4j-jdk14"
回答by nafg
libraryDependencies := libraryDependencies.value.map(_.exclude("groupid", "artifactname"))

![从 scala.collection.immutable.Iterable[String] 中删除第一个和最后一个元素](/res/img/loading.gif)