Sbt: set specific scalacOptions parameters when compiling tests

I usually use this set of parameters to compile 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 work poorly with ScalaTest, so I want to disable -Ywarn-dead-code and -Ywarn-value-discard when compiling tests.

I tried to add an area 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 parameters are disabled for the normal compilation area, and the last ones do not affect the test compilation parameters.

How can I have a separate parameter list when compiling tests?

+7
scala sbt
source share
2 answers

If the same problem, @Mike Slinn's answer didn't work for me. I believe test options extend compilation options? In the end, this trick explicitly removed ignored options from the test

scalacOptions in Test --= Seq( "-Ywarn-dead-code", "-Ywarn-value-discard")

+4
source share

Why not define common parameters in a variable (which I called sopts ) and other parameters 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.

Since this question has remained unanswered for so long, and in between Scala 2.12 and 2.12.1 were released in between, I changed the general options to suit.

By the way, I have no problems with ScalaTest using the switches you mentioned. I only answered this question because it was interesting.

+3
source share

All Articles