sbt:在编译测试时设置特定的 scalacOptions 选项 [英] sbt: set specific scalacOptions options when compiling tests
问题描述
通常我使用这组选项来编译 Scala 代码:
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"
)
但是其中一些不能很好地与 ScalaTest 配合使用,所以我想在编译时禁用 -Ywarn-dead-code
和 -Ywarn-value-discard
测试.
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.
我尝试添加这样的范围
scalacOptions in Compile ++= Seq(...)
或
scalacOptions in (Compile, compile) ++= Seq(...)
甚至
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?
推荐答案
遇到了同样的问题,@Mike Slinn 的回答对我不起作用.我相信测试选项扩展了编译选项?最终的诀窍是从测试中明确删除被忽略的选项
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")
这篇关于sbt:在编译测试时设置特定的 scalacOptions 选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!