Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

scala

slf4j

sbt

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?

like image 249
wks Avatar asked Jun 09 '12 03:06

wks


People also ask

How do you exclude Commons from logging?

To switch off commons-logging is easy: just make sure it isn't on the classpath at runtime. In Maven terms you exclude the dependency, and because of the way that the Spring dependencies are declared, you only have to do that once.

What is Ivy in sbt?

sbt (through Ivy) verifies the checksums of downloaded files by default. It also publishes checksums of artifacts by default. The checksums to use are specified by the checksums setting.

How does sbt resolve dependencies?

Background. update resolves dependencies according to the settings in a build file, such as libraryDependencies and resolvers . Other tasks use the output of update (an UpdateReport ) to form various classpaths. Tasks that in turn use these classpaths, such as compile or run , thus indirectly depend on update .

What does provided mean in build SBT?

sbt file. The “provided” keyword indicates that the dependency is provided by the runtime, so there's no need to include it in the JAR file.


4 Answers

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!
like image 194
drexin Avatar answered Oct 06 '22 06:10

drexin


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

excludeDependencies += "commons-logging" % "commons-logging"
like image 42
Eugene Yokota Avatar answered Oct 06 '22 07:10

Eugene Yokota


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"))
like image 37
lily LIU Avatar answered Oct 06 '22 05:10

lily LIU


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

libraryDependencies += "foo" %% "bar" % "1.2.3" intransitive
like image 39
Heiko Seeberger Avatar answered Oct 06 '22 07:10

Heiko Seeberger