Allow `targetExclude` to be passed a directory (`Directory`, `DirectoryProperty`, `Provider<Directory>`, etc.)
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)
https://github.com/diffplug/spotless/blob/d3a160d8d9f3576cca751344e91d14b0d33beb2e/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java#L1078
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(...)).
seems like a good idea, PR's welcome
Having not fully understood the issue, I’m wondering if it’s related to normalizing the directories as well.
I’m also assuming this approach would only handle one level of directories. If a directory contains subdirectories, those wouldn’t be handled correctly, and the same issue would likely occur.
- https://github.com/diffplug/spotless/pull/2691