Normally I use this set of options for compiling Scala code:
scalacOptions ++= Seq(
"-deprecation",
"-encoding", "UTF-8",
"-feature",
"-unchecked",
"-language:higherKinds",
"-language:implicitConversions",
"-Xfatal-warnings",
"-Xlint",
"-Yinline-warnings",
"-Yno-adapted-args",
"-Ywarn-dead-code",
"-Ywarn-numeric-widen",
"-Ywarn-value-discard",
"-Xfuture",
"-Ywarn-unused-import"
)
But some of them don't play well with ScalaTest, so I would like to disable -Ywarn-dead-code
and -Ywarn-value-discard
when compiling tests.
I tried adding scope like this
scalacOptions in Compile ++= Seq(...)
or
scalacOptions in (Compile, compile) ++= Seq(...)
or even
val ignoredInTestScalacOptions = Set(
"-Ywarn-dead-code",
"-Ywarn-value-discard"
)
scalacOptions in Test ~= { defaultOptions =>
defaultOptions filterNot ignoredInTestScalacOptions
}
but the first two disable options for normal compile scope as well while the latter doesn't affect tests compilation options.
How could I have a separate list of options when compiling tests?
Had the same issue, @Mike Slinn answer didn't work for me. I believe the test options extend the compile options? What eventually did the trick was explicitly removing ignored options from test
scalacOptions in Test --= Seq(
"-Ywarn-dead-code",
"-Ywarn-value-discard")
Why not define common options in a variable (which I called sopts
), and other options in another variable (which I called soptsNoTest
)?
val sopts = Seq(
"-deprecation",
"-encoding", "UTF-8",
"-feature",
"-target:jvm-1.8",
"-unchecked",
"-Ywarn-adapted-args",
"-Ywarn-numeric-widen",
"-Ywarn-unused",
"-Xfuture",
"-Xlint"
)
val soptsNoTest = Seq(
"-Ywarn-dead-code",
"-Ywarn-value-discard"
)
scalacOptions in (Compile, doc) ++= sopts ++ soptsNoTest
scalacOptions in Test ++= sopts
Tested with SBT 0.13.13.
Because this question has been unanswered for so long, and Scala 2.12 and 2.12.1 were released in the interim, I modified the common options to suit.
BTW, I do not experience any problem with ScalaTest using the switches you mention. I only answered this question because it was interesting.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With