Skip to content

Allow targetExclude to be passed a directory (Directory, DirectoryProperty, Provider<Directory>, etc.) #2667

@bric3

Description

@bric3

One could be tempted to exclude a directory via targetExclude, e.g. project.layout.buildDirectory

spotless {
  scala {
    toggleOffOn()
    targetExclude(project.layout.buildDirectory)
    scalafmt('2.7.5').configFile(configPath + '/enforcement/spotless-scalafmt.conf')
  }
}

However this doesn't work as it's not handled specifically. So when the task is configured, it uses the dir as a regular "file", and the operation here does nothing (target and targetExclude are FileCollection)

FileCollection totalTarget = targetExclude == null ? target : target.minus(targetExclude);

The alternative is to expand this to a FileTree before passing it to targetExclude. In this case the operation above correctly removes the files nested under the directory.

-    targetExclude(project.layout.buildDirectory)
+    targetExclude(project.layout.buildDirectory.asFileTree)

However, I believe that spotless could do that automatically, if the type is known to represent a directory.


On another note I tried to pass a Provider<String> (targetExclude(genDirectory.map { it.asFile.path + "/**/*.scala" })), but this was interpreted as a single file (because the value is passed to project.files(...)).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions