有没有一种简单的方法可以在 SBT 中指定全局依赖排除 [英] Is there a simple way to specify a global dependency exclude in SBT
问题描述
如何在全局范围内排除传递依赖?我的项目依赖于很多 Twitter 库或依赖于 Twitter 库的库.我不希望 slf4j-jdk14
在我的类路径中,无论如何(我使用 logback 作为 slf4j 绑定).
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-jdk14
in my classpath, no matter what (I use logback as slf4j binding).
目前我这样做:
"com.twitter" %% "finagle-thriftmux" % "6.16.0" exclude("org.slf4j", "slf4j-jdk14")
但每次有人添加另一个使用 slf4j-jdk14
的依赖项时,我可能会将其重新放入类路径中.
but every time someone adds another dependency that uses slf4j-jdk14
I might get it back into the classpath.
推荐答案
自 sbt 0.13.8
在 sbt 0.13.8 中有 可能性 全局排除依赖项.这是一个紧凑的例子:
In sbt 0.13.8 there is possibility to exclude dependencies globally. Here is a compact example:
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.
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"))
这篇关于有没有一种简单的方法可以在 SBT 中指定全局依赖排除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!