53

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?

wks
  • 1,158
  • 1
  • 7
  • 12

4 Answers4

70

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!
drexin
  • 24,225
  • 4
  • 67
  • 81
  • 29
    It works. And my final solution is `libraryDependencies ++= Seq(...).map(_.exclude("commons-logging", "commons-logging"))` – wks Jun 10 '12 at 16:31
  • 3
    The documentation for this is here: http://www.scala-sbt.org/release/docs/Detailed-Topics/Library-Management#exclude-transitive-dependencies – Chris Martin Jan 17 '13 at 17:23
  • 1
    Update: Recent versions of sbt (since 0.13?) supports "provided", too. I can just write `"commons-logging" % "commons-logging" % "1.2" % "provided"` – wks Nov 16 '19 at 05:43
28

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

excludeDependencies += "commons-logging" % "commons-logging"
Eugene Yokota
  • 94,654
  • 45
  • 215
  • 319
7

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"))
lily LIU
  • 119
  • 1
  • 5
2

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

libraryDependencies += "foo" %% "bar" % "1.2.3" intransitive
Heiko Seeberger
  • 3,702
  • 21
  • 20
  • 10
    Downvoted, cause can lead to the problems when you have more than one 3rd party dependencies, as drexin noted, sorry. – om-nom-nom Jun 09 '12 at 08:39
  • This solution actually worked for me (removed all the 3rd party dependencies for 1 explicit dependency). – Jane Wayne Dec 12 '16 at 21:40