如何从 scala/sbt/slf4j 项目中排除 commons-logging?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10958215/
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
How to exclude commons-logging from a scala/sbt/slf4j project?
提问by wks
My scala/sbt project uses grizzled-slf4j and logback. A third-party dependency uses Apache Commons Logging.
我的 scala/sbt 项目使用 grizzled-slf4j 和 logback。第三方依赖项使用 Apache Commons Logging。
With Java/Maven, I would use jcl-over-slf4j and logback-classic so that I can use logback as the unified logging backend.
对于 Java/Maven,我将使用 jcl-over-slf4j 和 logback-classic,以便我可以使用 logback 作为统一的日志记录后端。
I would also eliminate the commons-logging dependency that the third-party lib would let sbt pull in. I do the following in Maven (which is recommended by http://www.slf4j.org/faq.html#excludingJCL):
我还将消除第三方库让 sbt 引入的 commons-logging 依赖项。我在 Maven 中执行以下操作(由http://www.slf4j.org/faq.html#exclusiveJCL推荐):
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
<scope>provided</scope>
</dependency>
And the question is, how to do the same with sbt?
问题是,如何用 sbt 做同样的事情?
回答by drexin
Heiko's approach will probably work, but will lead to none of the dependencies of the 3rd party lib to be downloaded. If you only want to exclude a specific one use exclude.
Heiko 的方法可能会奏效,但不会导致下载第 3 方库的任何依赖项。如果您只想排除特定的一种,请使用exclude.
libraryDependencies += "foo" % "bar" % "0.7.0" exclude("org.baz", "bam")
or
或者
... excludeAll( ExclusionRule(organization = "org.baz") ) // does not work with generated poms!
回答by Eugene Yokota
For sbt 0.13.8 and above, you can also try the project-level dependency exclusion:
对于 sbt 0.13.8 及以上版本,还可以尝试项目级依赖排除:
excludeDependencies += "commons-logging" % "commons-logging"
回答by Heiko Seeberger
Add intransitiveyour 3rd party library dependency, e.g.
添加不及物你的 3rd 方库依赖,例如
libraryDependencies += "foo" %% "bar" % "1.2.3" intransitive
回答by lily LIU
I met the same problem before. Solved it by adding dependency like
我以前遇到过同样的问题。通过添加依赖项来解决它
libraryDependencies += "foo" % "bar" % "0.7.0" exclude("commons-logging","commons-logging")
or
或者
libraryDependencies += "foo" % "bar" % "0.7.0" excludeAll(ExclusionRule(organization = "commons-logging"))

