-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add mechanism to allow excluding sourceset directories #362
Comments
Thanks for the great explanation and I'm always open to contributions. I take it the main need here is for people to be able exclude source code which is generated by other gradle plugins or frameworks? Is the most common pattern for these frameworks to generate source code which is part of the existing main sourceSet and place those kt files in the gradle |
Thanks for taking the time to respond!
Yes, in a way that satisfies the stricter task-ordering requirements in gradle 8+.
I don't know if that's the most common pattern, but I do see it happen with a few different plugins that we're using. In at least one of these, yes, there is a bidirectional dependency with non-generated source. But even if it does end up in a different sourceset, the linting task for that sourceset would still run by default, right? Were you thinking that consumers would disabling the linting task for the generated code sourceset explicitly? I ran into some minor difficulties with my original approach and am refining it somewhat. Once I have it fully validated I'll put up a PR and we can iterate on it as you see fit. |
Ok, this is good information. I like the approach you are proposing. It makes a lot of sense we wouldn't want to lint files placed in a build directory. Thanks for the proposal and looking forward to the PR. |
Sorry for the long delay here. In the end I couldn't get this working in a generic enough way that worked for all scenarios. I have a formulation that worked in a lot of cases for us, but there were still some repos where it failed and I was having a really hard time figuring out what gradle was doing to cause it to fail. In the end I didn't have time to keep digging and so worked around it in those projects. I'm providing the formulation here in case it's useful to somebody but at this point I don't have cycles to get it to the point where I could propose a change to kotlinter. For context, this code is applied in one our organization's "convention plugins" (or rough equivalent), so that it overrides behaviour in projects that have kotlinter/ktfmt applied. The idea was to upstream this so we wouldn't need this override.
|
Thank you for the detailed formula. Definitely helpful in thinking about an enhancement. |
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:
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 usedependsOn
ormustRunAfter
to define an ordering betweenkotlinter
andFoo
even if you use the above exclude mechanism, because it still consideredkotlinter
as "using" the generated folder thatFoo
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 ofproject.provider { directorySet }
. This filters out the generated folder thatFoo
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 theproject.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.The text was updated successfully, but these errors were encountered: