如何从scala/sbt/slf4j项目中排除commons-logging?

wks*_*wks 47 scala slf4j sbt

我的scala/sbt项目使用了grizzled-slf4j和logback.第三方依赖项使用Apache Commons Logging.

使用Java/Maven,我会使用jcl-over-slf4j和logback-classic,这样我就可以使用logback作为统一的日志记录后端.

我还将消除第三方库将允许sbt拉入的commons-logging依赖.我在Maven中执行以下操作(由http://www.slf4j.org/faq.html#excludingJCL推荐):

<dependency>
    <groupId>commons-logging</groupId>
    <artifactId>commons-logging</artifactId>
    <version>1.1.1</version>
    <scope>provided</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)

问题是,如何与sbt做同样的事情?

dre*_*xin 65

Heiko的方法可能会起作用,但不会导致第三方lib的依赖性下载.如果您只想排除特定的一个用途exclude.

libraryDependencies += "foo" % "bar" % "0.7.0" exclude("org.baz", "bam")
Run Code Online (Sandbox Code Playgroud)

要么

... excludeAll( ExclusionRule(organization = "org.baz") ) // does not work with generated poms!
Run Code Online (Sandbox Code Playgroud)

  • 有用.我的最终解决方案是`libraryDependencies ++ = Seq(...).map(_.exclude("commons-logging","commons-logging")) (27认同)
  • 相关文档如下:http://www.scala-sbt.org/release/docs/Detailed-Topics/Library-Management#exclude-transitive-dependencies (3认同)

Eug*_*ota 20

对于sbt 0.13.8及更高版本,您还可以尝试项目级依赖项排除:

excludeDependencies += "commons-logging" % "commons-logging"
Run Code Online (Sandbox Code Playgroud)


小智 5

我以前遇到过同样的问题。通过添加依赖项来解决它

libraryDependencies += "foo" % "bar" % "0.7.0" exclude("commons-logging","commons-logging")
Run Code Online (Sandbox Code Playgroud)

或者

libraryDependencies += "foo" % "bar" % "0.7.0" excludeAll(ExclusionRule(organization = "commons-logging"))
Run Code Online (Sandbox Code Playgroud)