diffplug / spotless

Keep your code spotless
Apache License 2.0
4.47k stars 453 forks source link

Groovy formatting with Spotless leaves a temporary directory #2019

Open attiand opened 8 months ago

attiand commented 8 months ago

Running ./mvnw spotless:apply with spotless setup to format Groovy a temporary directory is left in the root. See the following reproducer project: https://github.com/attiand/spotless-tmp-file-issue

I would have no problem if the plugin left temporary directories in the Maven target directory, but it is annoying in the project root.

The file was named like this: file%3A%2Ftmp%2Fspotless-groovy10387858394287009044%2F

mojavelinux commented 5 months ago

The problem appears to be with this line https://github.com/diffplug/spotless/blob/main/lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java#L61 where it creates the temporary directory for osgi/equinox. However, when I print the value it's passing in, it does not have the file:// prefix. So it's perhaps an issue somewhere in the called code. What I can tell you is that removing this property from the map fixes the problem. But I don't know where it ends up putting the properties in that case.

mojavelinux commented 5 months ago

Aha, it puts the files under the workspace folder in the current working directory. When the location is not specified, though, we don't get any weird file%3A directories. So perhaps this really is an issue in Equinox that is being inherited. :thinking:

cooper15 commented 4 months ago

Hi there, I'm facing this issue, and I was wondering 2 things:

  1. @mojavelinux you mentioned that the current working directory is used when the location is not specified. Can we currently provide a custom location as a workaround? I couldn't find any documentation regarding that point.
  2. I was thinking if we can pass target or build to this line Files.createTempDirectory("target/spotless-groovy").toAbsolutePath().toString() so when the absolute path is resolved it will go directly to the build location.
mojavelinux commented 4 months ago

@mojavelinux you mentioned that the current working directory is used when the location is not specified. Can we currently provide a custom location as a workaround? I couldn't find any documentation regarding that point.

I did not develop, nor do I maintain this project, so I cannot speak to any workarounds. I only offered suggestions about what might be going wrong based on my observations. The only workaround I know of is to delete the temporary directory after spotless runs.

ikysil commented 1 month ago

FYI - this issue is reproducible when running tests of spotless itself ./gradlew test. The directories are created under lib-extra folder.