【问题标题】:How to exclude commons-logging from a scala/sbt/slf4j project?如何从 scala/sbt/slf4j 项目中排除公共日志记录?
【发布时间】:2017-05-20 04:38:44
【问题描述】:

我的 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>

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

【问题讨论】:

    标签: scala sbt slf4j


    【解决方案1】:

    Heiko 的方法可能会奏效,但不会导致第 3 方库的任何依赖项都不会被下载。如果您只想排除特定的一个,请使用exclude

    libraryDependencies += "foo" % "bar" % "0.7.0" exclude("org.baz", "bam")
    

    ... excludeAll( ExclusionRule(organization = "org.baz") ) // does not work with generated poms!
    

    【讨论】:

    • 它有效。我的最终解决方案是libraryDependencies ++= Seq(...).map(_.exclude("commons-logging", "commons-logging"))
    • 更新:最新版本的 sbt(从 0.13 开始?)也支持“提供”。我可以写"commons-logging" % "commons-logging" % "1.2" % "provided"
    【解决方案2】:

    对于sbt 0.13.8及以上,也可以尝试项目级的依赖排除:

    excludeDependencies += "commons-logging" % "commons-logging"
    

    【讨论】:

      【解决方案3】:

      我以前遇到过同样的问题。通过添加像

      这样的依赖来解决它
      libraryDependencies += "foo" % "bar" % "0.7.0" exclude("commons-logging","commons-logging")
      

      libraryDependencies += "foo" % "bar" % "0.7.0" excludeAll(ExclusionRule(organization = "commons-logging"))
      

      【讨论】:

        【解决方案4】:

        添加 intransitive 您的 3rd 方库依赖项,例如

        libraryDependencies += "foo" %% "bar" % "1.2.3" intransitive
        

        【讨论】:

        • 投反对票,当您有多个第三方依赖项时,可能会导致问题,正如 drexin 指出的那样,抱歉。
        • 这个解决方案实际上对我有用(删除了 1 个显式依赖项的所有第 3 方依赖项)。
        猜你喜欢
        • 2022-07-02
        • 2011-01-23
        • 1970-01-01
        • 1970-01-01
        • 2014-09-27
        • 2012-08-26
        • 2011-11-07
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多