How to exclude commons-logging from a scala/sbt/slf4j project?

ScalaSbtSlf4j

Scala Problem Overview


My scala/sbt project uses grizzled-slf4j and logback. A third-party dependency uses 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.

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

<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?

Scala Solutions


Solution 1 - Scala

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.

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

or

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

Solution 2 - Scala

For sbt 0.13.8 and above, you can also try the project-level dependency exclusion:

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

Solution 3 - Scala

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

Solution 4 - Scala

Add intransitive your 3rd party library dependency, e.g.

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionwksView Question on Stackoverflow
Solution 1 - ScaladrexinView Answer on Stackoverflow
Solution 2 - ScalaEugene YokotaView Answer on Stackoverflow
Solution 3 - Scalalily LIUView Answer on Stackoverflow
Solution 4 - ScalaHeiko SeebergerView Answer on Stackoverflow