32

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).

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-jdk14 I might get it back into the classpath.

4

3 回答 3

49

excludeDependencies += "org.slf4j" % "slf4j-jdk14"

于 2016-08-05T18:11:53.560 回答
48

从 sbt 0.13.8 开始

在 sbt 0.13.8 中,可以全局排除依赖项。这是一个紧凑的例子:

excludeDependencies += "org.slf4j" % "slf4j-jdk14"

但是,在撰写本文时,此功能被标记为实验性的,因此了解较旧的解决方案是明智之举。

在 sbt 0.13.8 之前

对于一组依赖项,您可以按如下方式进行:

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"))
于 2014-09-09T15:39:33.657 回答
6
libraryDependencies := libraryDependencies.value.map(_.exclude("groupid", "artifactname"))
于 2016-03-30T06:09:05.633 回答