-
Notifications
You must be signed in to change notification settings - Fork 464
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
Build output directory is not excluded in Windows in Spotless 4.0.x #585
Comments
Interesting! The culprit PR must be #576, but I don't see how it caused the regression. How does the code-generation work? Based on the configuration you copy-pasted, I would expect autogenerated files in configure<SpotlessExtension> {
java {
targetExclude 'build/**'
googleJavaFormat()
}
} Without knowing more about your code generation, it looks like this may have been a bug in 3.x, which is now fixed in 4.x on Windows, but still broken on 4.x unix. A repo that reproduces the issue would be helpful to resolve the confusion. |
As per your suggestion, I tried adding configure<SpotlessExtension> {
java {
targetExclude(files("$buildDir/**"))
googleJavaFormat()
}
} but it made no difference in Windows. The same build error happened. |
The code generation is done with val VERSION: String by project
val constantsDir = File(project.buildDir, "generated/src/constants/java")
tasks.register("constantsGenerator") {
val outputFile = File(constantsDir, "project/Version.java")
inputs.property("version", VERSION as String)
outputs.file(outputFile)
doLast {
outputFile.parentFile.mkdirs()
outputFile.writeText("package project;\n" +
"/** Holds the current build version. */\n" +
"public final class Version {\n" +
" private Version() {}\n" +
"\n" +
" public static final String VERSION = \"$VERSION\";\n" +
"}\n")
}
}
tasks.named("compileJava").configure {
dependsOn(tasks.named("constantsGenerator"))
}
sourceSets.main {
java.srcDir(constantsDir)
} So, the directory is considered regular source input. |
It seems I'm facing the same issue: build passes on Linux and MacOS, but fails on Windows.
|
@valfirst turns out your bug is unrelated to @davidburstromspotify's issue. Thanks for reporting though, it was useful, and we have a fix in #588. You will see vastly improved performance adopting the next version once it is published. @davidburstromspotify I tried to reproduce, and here was what I observed:
|
The |
Just to confirm, I had the exact same problem as before:
I did also see the DirectoryNotEmptyException at some point while trying out different combos, so I'm happy to see that is fixed. |
Oh! I just realized. Something strange is going with your target. Looks like you need |
If you have this in some shared/root script: configure<SpotlessExtension> {
java {
targetExclude(files("$buildDir/**"))
googleJavaFormat()
}
} it might be that you're getting the absolute path of the root build directory put in there, and it's not applying correctly to subprojects. Same thing might be happening with your code generation, it looks your root project has |
Nope, the |
Here's a repo that I have tested on Mac and Windows. https://github.com/davidburstromspotify/spotless-issue-585 |
I cloned your example repo, on win and mac. I believe it is all operating as expected. You are configuring your spotless in a So I would expect that all of them would fail except for The only thing I don't understand is why this ever worked in |
Are you entirely sure about this? The
the output is the expected
i.e. a file in the Could it be that I'd say that using |
Aha, you are correct! Still no idea how this worked in 3.30.0, but this is the code to parse target and targetExclude: spotless/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java Lines 194 to 232 in 204c547
Note that it is all This was confusing and hard to debug, which means the design isn't very good. But in the design's defense, it is documented pretty clearly. Also, it's been this way forever, so it's very difficult to change. Thanks for sticking with this, it's a helpful example of how our API is confusing, but I'm not sure what we can do to improve it. Open to backward-compatible suggestions! |
The Happy to discuss further ways to make target/targetExclude easier to use, but I think the |
Thanks for the investigation! Well, at least there is a workaround. Maybe it is not the right forum, but I also wanted to check with you what's up with GJF flagging the generated file as wrongly formatted when it is in fact identical (except for a suffix) to the https://github.com/davidburstromspotify/spotless-issue-585/blob/master/version/src/main/java/project/Version2.java file. |
A suffix is enough to make a file dirty. |
No, I meant that Version.java and Version2.java are identical, except that there's a "2" in Version2.java. Try diffing them for yourself to see what I mean. The generated Version.java has no formatting issues but is still failing. |
Ah, I see what you're talking about. google-java-format has had win vs unix bugs in the past. For example, this is a thing we did to fix a windows bug in google-java-format 1.1 on Windows: spotless/lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java Lines 181 to 182 in e04fae5
We have several features in place to paper-over bugs in upstream formatters, but there's only so much we can do. Always happy to take a PR to correct any platform-dependent behavior. One possible fix is to try a different version, e.g. |
Hm, interesting. The weird thing here is that in my repro-repo, this applies on Mac as well. In any of the scenarios commented with |
Version 5.8.2 works correctly, as far as I can tell. |
Summary:
Spotless runs on build output files in Windows. The same project passes in Linux and MacOS.
Gradle version: 6.5.1-rc1
Spotless version: 4.0.0 and 4.0.1
Regression when moving from version: 3.30.0
Operating System: Windows Server 2012
Build has standard
googleJavaFormat
applied.Build output:
The text was updated successfully, but these errors were encountered: