我想你真的很接近。以下是一些细节:
- sbt 下载库依赖项和编译器插件都使用
Compile
配置的update
任务,该任务使用libraryDependencies
设置。addCompilerPlugin
是libraryDependencies
withCompilerPlugin
配置的简写。
- 编译器插件需要
scalaOptions
您感兴趣的配置。
- 您需要从中获取
sources
才能Compile
在Lint
.
如果您看到wartremoverSettings
它的实现同时执行addCompilerPlugin
和scalacOptions
. 您有两个选项可以禁用 wartremover Compile
:
- 使用自动插件(需要 sbt 0.13.5+)注入
wartremoverSettings
,然后手动从Compile
.
- 禁用自动插件,然后手动将疣去除剂添加到
libraryDependencies
.
这是第一个选项。
项目/build.properties
sbt.version=0.13.7
项目/wart.sbt
addSbtPlugin("org.brianmckenna" % "sbt-wartremover" % "0.11")
构建.sbt
lazy val Lint = config("lint") extend Compile
lazy val foo = project.
configs(Lint).
settings(inConfig(Lint) {
Defaults.compileSettings ++ wartremover.wartremoverSettings ++
Seq(
sources in Lint := {
val old = (sources in Lint).value
old ++ (sources in Compile).value
},
wartremover.wartremoverErrors := wartremover.Warts.all
) }: _*).
settings(
scalacOptions in Compile := (scalacOptions in Compile).value filterNot { _ contains "wartremover" }
)
foo/src/main/scala/Foo.scala
package foo
object Foo extends App {
// Won't compile: Inferred type containing Any
val any = List(1, true, "three")
println("hi")
}
样本输出
foo> clean
[success] Total time: 0 s, completed Dec 23, 2014 9:43:30 PM
foo> compile
[info] Updating {file:/quick-test/wart/}foo...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Compiling 1 Scala source to /quick-test/wart/foo/target/scala-2.10/classes...
[success] Total time: 1 s, completed Dec 23, 2014 9:43:33 PM
foo> run
[info] Running foo.Foo
hi
[success] Total time: 0 s, completed Dec 23, 2014 9:43:37 PM
foo> lint:compile
[info] Compiling 1 Scala source to /quick-test/wart/foo/target/scala-2.10/lint-classes...
[error] /quick-test/wart/foo/src/main/scala/Foo.scala:5: Inferred type containing Any
[error] val any = List(1, true, "three")
[error] ^
[error] /quick-test/wart/foo/src/main/scala/Foo.scala:5: Inferred type containing Any
[error] val any = List(1, true, "three")
[error] ^