-
Notifications
You must be signed in to change notification settings - Fork 51
Description
Sort of related to #208 and #242 . Currently the exclude mechanism allow you to exclude paths, however those paths are still considered as part of the "task input" from gradle's perspective. This is because even if you do something like:
project.tasks.withType(FormatTask::class.java) { task ->
task.exclude {
it.file.path.contains("/generated/")
}
}
which excludes all ".../generated/..." files, the Gradle code here still takes the root of the filecollection as a task input.
In Gradle 8+ this can cause issues because it forces task ordering when you have tasks reading/writing the same files. So for example if you apply plugin Foo and it generates files into $buildDir/generated/foo/ then gradle will force you to use dependsOn or mustRunAfter to define an ordering between kotlinter and Foo even if you use the above exclude mechanism, because it still considered kotlinter as "using" the generated folder that Foo is writing to.
After some experimentation, it seems that this can be corrected by applying a filter earlier, on this line by doing something like ... project.provider { directorySet.filterNot { dir -> dir.path.contains("/generated/") } } ... instead of project.provider { directorySet }. This filters out the generated folder that Foo adds to the sourcesets, and so Gradle never sees it as an input to kotlinter at all.
@jeremymailen Would you be open to taking a patch along these lines? I was thinking of (a) adding a boolean flag to the plugin extension like excludeBuildFiles = false and (b) if the flag is set to true, I would modify the project.provider as above but to filter out any source set directories that are inside the project build dir. Of course more complex options are possible by allowing consumers of kotlinter to provide a custom exclusion filter in the extension but I don't know if you want to allow that. The build-dir-exclusion flag would be sufficient for our purposes.