Skip to content
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

Help SpotlessTask to handle a removed directory. #589

Merged
merged 1 commit into from
Jun 1, 2020
Merged

Conversation

nedtwigg
Copy link
Member

@bigdaz in a local build with Gradle 6.4.1, I was getting this error:

Caused by: java.nio.file.DirectoryNotEmptyException: C:\Users\ntwigg\Documents\dev\test\build\spotless\spotlessJava\...

so I added special handling for directories. I was a little surprised, I figured that Gradle would pass removed subfolders and such so that you could always just do Files.deleteIfExists().

Unfortunately, I wasn't able to recreate in an integration test. It's surprising, because I had a very simple one that recreated the DirectoryNotEmptyException every single time, but it never triggered the error when running via testkit:

plugins {
    id 'java'
    id 'com.diffplug.gradle.spotless'
}

def generatedDir = new File(project.buildDir, "generated/src/constants/java")
def outputFile = new File(generatedDir, "project/Version.java")
outputFile.getParentFile().mkdirs()
outputFile.setText("package blah; public class Version {}");

sourceSets.main {
    java.srcDir(generatedDir)
}

spotless {
    java {
        targetExclude 'build/**' // comment and uncomment to generate DirectoryNotEmptyException
        googleJavaFormat()
    }
}

Regardless, this small change fixes it and seems harmless. Does this smell right to you?

@nedtwigg nedtwigg merged commit 294b602 into master Jun 1, 2020
nedtwigg added a commit that referenced this pull request Jun 1, 2020
@nedtwigg nedtwigg deleted the feat/removedDir branch June 1, 2020 19:51
@bigdaz
Copy link
Contributor

bigdaz commented Jun 1, 2020

Good catch @nedtwigg and my bad. I can see how this would happen if you removed a source directory that contained files that had previously produced output.

When a source directory has been removed, it's probably fine to recursively delete the output. But we should revisit this mechanism when we move to the improved InputChanges API. I'm hoping to find some time to work on Spotless v5.0 soon.

@nedtwigg
Copy link
Member Author

nedtwigg commented Jun 1, 2020

Released in plugin-gradle 4.1.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants