Is there a simple way to specify a global dependency exclude in SBT

廉价感情. 提交于 2020-05-24 21:06:07

问题


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.


回答1:


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

Before 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"))



回答2:


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




回答3:


libraryDependencies := libraryDependencies.value.map(_.exclude("groupid", "artifactname"))


来源:https://stackoverflow.com/questions/25747900/is-there-a-simple-way-to-specify-a-global-dependency-exclude-in-sbt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!