dau*_*ama 2 scala sbt scalastyle
我在这个主题上发现的所有其他问题都很老。
我正在使用sbt该scala-style插件构建一个 Scala 项目,但我找不到一种方法来排除我有一些生成代码的特定文件夹。
有没有办法强制插件不检查该特定文件夹?
现在我正在手动编辑文件并添加:
// scalastyle:off
在文件的顶部,但这很烦人。
在官方网站http://www.scalastyle.org/sbt.html我找不到任何文档,尽管似乎实际上可以从中排除路径/文件。
所以看起来我们实际上可以通过:
println(" -x, --excludedFiles STRING regular expressions to exclude file paths (delimited by semicolons)")
Run Code Online (Sandbox Code Playgroud)
在我的build.sbt电话中:
lazy val compileScalastyle = taskKey[Unit]("compileScalastyle")
compileScalastyle := org.scalastyle.sbt.ScalastylePlugin.scalastyle.in(Compile).toTask("").value
(compile in Compile) <<= (compile in Compile) dependsOn compileScalastyle
Run Code Online (Sandbox Code Playgroud)
有没有办法用 来实现sbt plugin?
您可以获取“src/main/scala”下的所有文件/目录并过滤掉您的目录:
lazy val root = (project in file(".")).
settings(
(scalastyleSources in Compile) := {
// all .scala files in "src/main/scala"
val scalaSourceFiles = ((scalaSource in Compile).value ** "*.scala").get
val fSep = java.io.File.separator // "/" or "\"
val dirNameToExclude = "com" + fSep + "folder_to_exclude" // "com/folder_to_exclude"
scalaSourceFiles.filterNot(_.getAbsolutePath.contains(dirNameToExclude))
}
)
Run Code Online (Sandbox Code Playgroud)
编辑:
我添加了一个更“通用”的解决方案,它检查每个文件的路径以排除...
| 归档时间: |
|
| 查看次数: |
1085 次 |
| 最近记录: |