Reputation: 4347
All the other questions I've found on this topic are quite old.
I am building a scala project with sbt
and the scala-style
plugin but I can't find a way to exclude a specific folder where I have some generated code.
Is there a way to force the plugin to not check that particular folder?
Right now I am editing the files manually and adding:
// scalastyle:off
on the top of the file, but this is quite annoying.
In the official website http://www.scalastyle.org/sbt.html I couldn't find any documentation, although it seems that it is actually possible to exclude paths/files from it.
so it seems that we can actually pass:
println(" -x, --excludedFiles STRING regular expressions to exclude file paths (delimited by semicolons)")
In my build.sbt
I call:
lazy val compileScalastyle = taskKey[Unit]("compileScalastyle")
compileScalastyle := org.scalastyle.sbt.ScalastylePlugin.scalastyle.in(Compile).toTask("").value
(compile in Compile) <<= (compile in Compile) dependsOn compileScalastyle
Is there a way to achieve that with the sbt plugin
?
Upvotes: 2
Views: 1509
Reputation: 3922
You could get all files/directories under "src/main/scala" and filter out your directory:
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))
}
)
EDIT:
I've added a more "generic" solution where it checks the path of each file to exclude...
Upvotes: 5