drobert
drobert

Reputation: 1310

sbt Test scope includes Runtime?

I'm configuring SLF4J within an SBT application and the Test vs Runtime scopes are working differently than I'd expect.

The setup I want:

Relevant build.sbt (sbt 0.13) section:

libraryDependencies += "org.slf4j" % "slf4j-simple" % "1.7.25" % Test,
libraryDependencies += "org.apache.logging.log4j" % "log4j-api" % 2.8.2 % Runtime,
libraryDependencies += "org.apache.logging.log4j" % "log4j-core" % 2.8.2 % Runtime,
libraryDependencies += "org.apache.logging.log4j" % "log4j-slf4j-impl" % 2.8.2 % Runtime

The error I'm getting is that there are two slf4j bindings present, the log4j one and the simple.

I'm wondering how the Runtime dependencies can be excluded from the Test scope, or if this is the wrong approach here.

To distill the question: I want to use a few different jars at runtime vs test that are mutually exclusive. How can this be done in sbt 0.13?

Upvotes: 1

Views: 1181

Answers (1)

marios
marios

Reputation: 8996

The issue is that Test scope includes Compile and presumably Runtime. So anything you add in Runtime it's also added in Test.

You can try to exclude log4j-slf4j-impl from the Test classpath like this:

fullClasspath.in(Test) := fullClasspath.in(Test).value.filterNot(_.data.getName.contains("log4j-slf4j-impl"))

Upvotes: 1

Related Questions