-
Notifications
You must be signed in to change notification settings - Fork 461
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
Gradle: can't targetExclude files in the buildDir #399
Comments
Hmmm... so spotless/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java Lines 176 to 198 in 9843130
And then calls super, which is this: spotless/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java Lines 569 to 581 in 9843130
So the exclusion should still happen. The reason it's failing is that spotless/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java Lines 152 to 154 in 9843130
Which excludes spotless/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java Lines 190 to 201 in 9843130
This is good when we're parsing targets, e.g. By supplying a The complicated parse logic is pretty nasty, and has caused surprises before. But there are lots of wildcard Maybe a good way to handle this would be if those complicated exclusions only happened if |
How about passing a boolean to |
That could work too. I think the first proposal is closer to the root cause, and the second proposal is a bit more of a patch. The root cause is that the parsing logic assumes the user was lazy, and didn't really mean to include Can we think of a String where the change I have proposed would be a problem for an existing target? The only one I can think of is |
I agree for For example, |
For the hypothetical buildscript where I did |
is there any workaround how to currently exclude generated sources? |
@redhead Yes, given in the original report above. (Sorry about the close/reopen, I mistapped on my phone) |
Resolved by #457 and released in |
I tried to use the OP's original non-working solution, thinking that #457 would make it work, but no luck.
I'm using gradle spotlees plugin 6.4.2 This is a multi-module gradle build, where spotless is configured in the root build file. |
I stepped through the build in a debugger and found that the problem lies in SpotlessTaskImpl.getOutputFile(). The call to FormatExtension.relativize returns null, which causes the exception to be thrown. relativize returns null because the targetExclude is not a child of the subproject directory in a multi-module build. So targetExclude can't be used to exclude generated sources from a multi-module build, because the build output is at the root directory, not the subproject directory. |
I have a project where some Java source files are generated by a task; they're generated into
build/generated-sources/
and added to a source set to later be compiled (like any other source files). I don't want those generated source files to be checked, but settingtargetExclude("build/generated-sources/**/*.java")
doesn't work.This is using Gradle 5.4.1 and Spotless 3.23.0 on Linux.
The way
java()
works,target
is set to includeallJava
sources for all source sets, irrespective of their location (contrary to setting the target to an Ant-style pattern, which will exclude files in thebuildDir
).The problem is that
targetExclude()
works the same astarget()
and will also exclude thebuildDir
, sotargetExclude("build/generated-sources/**/*.java")
will result in an emptyFileTree
, and my generated sources will be checked by Spotless.I found a workaround by using a
FileTree
, which won't go through that code that excludes thebuildDir
:But the special exclusions should only be applied to the
target
, nottargetExclude
.To reproduce, no need for a task generating source code: put some malformed Java source file somewhere in the
buildDir
(e.g.$buildDir/generated-sources/test/Foo.java
) and include it in a source set:The text was updated successfully, but these errors were encountered: