WartRemover是一个scalac插件.通常它是通过sbt插件配置的.
我希望能够在我的sbt项目上运行WartRemover作为单独的配置或任务,而不会影响通常的运行compile.
将Wartremover添加到我之后,我plugins.sbt尝试了以下几种变体.
lazy val Lint = config("lint").extend(Compile)
project("foo").
configs(Lint)
settings(inConfig(Lint)(Defaults.compileSettings): _*).
settings(inConfig(Linting)(wartremover.wartremoverSettings):_*).
settings(inConfig(Linting)(wartremover.wartremoverErrors := wartremover.Warts.all))
Run Code Online (Sandbox Code Playgroud)
后来scalacOptions大致包含了我在新lint配置和配置中的预期compile.但是,当我在调试模式下运行lint:compile并compile使用sbt时,我可以看到scalac的命令行参数,要么两个命令都导致-P:wartremover:...交换开关.这是令人惊讶的,因为只lint:scalacOptions显示了-P:wartremover:...开关.
如何创建单独的sbt配置或任务以使用WartRemover进行编译而不会影响compile:compile?
Eug*_*ota 10
我觉得你真的很亲密.以下是一些细节:
Compile配置update任务使用libraryDependencies设置下载库依赖项和编译器插件.addCompilerPlugin为简写libraryDependencies与CompilerPlugin配置.scalaOptions您感兴趣的配置.sources从Compile在使用它们Lint.如果你看到的执行wartremoverSettings它在做什么都addCompilerPlugin和scalacOptions.您有两个选项可以禁用wartremover Compile:
wartremoverSettings,然后手动删除wartremover编译器插件Compile.libraryDependencies.这是第一个选择.
sbt.version=0.13.7
Run Code Online (Sandbox Code Playgroud)
addSbtPlugin("org.brianmckenna" % "sbt-wartremover" % "0.11")
Run Code Online (Sandbox Code Playgroud)
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" }
)
Run Code Online (Sandbox Code Playgroud)
package foo
object Foo extends App {
// Won't compile: Inferred type containing Any
val any = List(1, true, "three")
println("hi")
}
Run Code Online (Sandbox Code Playgroud)
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] ^
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1033 次 |
| 最近记录: |