GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Spotless failed with OutOfMemory on large project (https://github.com/DataDog/dd-trace-java) · Issue #2788 · diffplug/spotless

Spotless failed with OutOfMemory on large project (https://github.com/DataDog/dd-trace-java) #2788

New issue
Copy link
New issue
Copy link
Closed
#2834
DataDog/dd-trace-java
#10456
DataDog/dd-trace-java#10456
Closed
Spotless failed with OutOfMemory on large project (https://github.com/DataDog/dd-trace-java)#2788
#2834
DataDog/dd-trace-java
#10456
Copy link

Description

@AlexeyKuznetsov-DD
AlexeyKuznetsov-DD
opened on Dec 10, 2025
Issue body actions

Follow-up to #2703 — OutOfMemoryError after upgrading to Spotless 8.1.0 and JDK 21

After upgrading Spotless from 6.13.0 to 8.1.0, along with migrating our Gradle build from JDK 8 to JDK 21, we started seeing OutOfMemoryError failures when running:

./gradlew spotlessApply

Observed Behavior

Spotless fails with OutOfMemoryError during formatting. Increasing the max heap from -Xmx4G to -Xmx6G allows the task to complete, but this is unexpectedly high for our project and suggests a memory leak or excessive retention.

Investigation

To better understand the issue, I captured a heap dump and analyzed it using Eclipse Memory Analyzer (MAT). The report highlights unusually high memory usage by the Groovy formatter:

1,682 instances of com.diffplug.spotless.extra.glue.groovy.GrEclipseFormatterStepImpl$GroovyErrorListener,
loaded by com.diffplug.spotless.FeatureClassLoader @ 0x6a46c02f0 occupy 2,079,056,168 (65.92%) bytes.

This strongly suggests that the Groovy formatter step is retaining large amounts of memory, potentially due to the error listener or related parsing structures.

Expected Behavior

Spotless should not require 6GB of heap to format our codebase. Prior versions ran successfully with 4GB. Memory usage should remain stable and not scale disproportionately.

Additional Context

  • JDK8 + 6.13.0 — works without issue
  • JDK21 + 8.1.0 — triggers OOM unless heap is increased.
  • Gradle version is 8.14.3

spotless configuration: https://github.com/DataDog/dd-trace-java/blob/a8d73887e079e0af17e60c037d580c2947d66dbf/build.gradle.kts#L28-L153

I can provide more info if needed.

Request

Could you please check if it is a regression in the Groovy formatter or a known issue with Spotless 8.x?

Thanks!

Reacted by Sarah Chen, Brice Dutheil and Bruce Bujon

Activity

  1. bric3 commented on Dec 11, 2025

    @bric3
    bric3
    on Dec 11, 2025
    Contributor
    More actions

    Note this is happening a repo that has ~600 projects, with various languages, but Groovy is in almost all of them, plus the gradle build scripts.

    spotless {
      project.pluginManager.withPlugin('groovy') {
        groovy {
          toggleOffOn()
          if (!groovySkipJavaExclude) {
            excludeJava() // excludes all Java sources within the Groovy source dirs from formatting
            // the Groovy Eclipse formatter extends the Java Eclipse formatter,
            // so it formats Java files by default (unless `excludeJava` is used).
          }
          targetExclude(buildDirectoryFiles)
          greclipse().configFile(configPath + '/enforcement/spotless-groovy.properties')
        }
      }
    }

    I profiled a Gradle daemon running on a large project, and I noticed some significant time spent in NestJars that in particular extract jar archives. Note the dependencies have already been downloaded in previous runs.

    Allocations
    Image

    CPU
    Image

    Monitor Blocked
    Image

    In a way looks related to that change ? #1524
    Maybe this is something that should be reported as well to https://github.com/equodev/equo-ide ? Maybe not as it might be an issue with spotless alone.

  2. bric3 commented on Dec 11, 2025

    @bric3
    bric3
    on Dec 11, 2025
    Contributor
    More actions

    Here's JFR file, with the above flamegraphs.

    8.14.3-spotless-8.1.0-spotlessApply.zip

    From the stack it looks like that spotless is trying to write something via com.diffplug.spotless.FormatterStepSerializationRoundtrip.HackClone.writeObject which ends up reading NestedJars ?

    Opening the profile in IntelliJ is quite useful as well.

    Image Image

    We can also see that, this behavior happens for the whole life time of Execution Worker threads.

  3. bric3 commented on Dec 11, 2025

    @bric3
    bric3
    on Dec 11, 2025
    Contributor
    More actions

    Using greclipse(), leeds to the creation of an EquoBasedStepBuilder which builds an EquoStep, with a FileSignature.Promised that is re-executed each time the state is requested, e.g. when spotless tries to serialize the configuration.

    Image Image

    Unfortunately this lazy computation of the state, has terrible performance impact.

    Reacted by Vincent Potuček
  4. bric3 commented on Dec 12, 2025

    @bric3
    bric3
    on Dec 12, 2025
    Contributor
    More actions

    In terms of workaround there's not much but using a different "step". I was able to successfully format groovy code with prettier, with prettier-plugin-groovy plugin (which is using beautify-groovy) but there's not a lot of control, and in the end makes files uglier.

    groovy {
      toggleOffOn()
      target("**/*.groovy")
      targetExclude(buildDirectoryFiles)
      prettier(["prettier" : "3.7.4", "prettier-plugin-groovy" : "0.2.1"]).configFile(configPath + '/prettier-groovy.toml')
    }
    # prettier-groovy.toml
    # Reads the .editorconfig file in the project root for base settings
    
    #trailingComma = "es5"
    #tabWidth = 2
    #semi = false
    #singleQuote = true
    
    plugins = [
      "prettier-plugin-groovy", # https://www.npmjs.com/package/prettier-plugin-groovy
    ]
    
    [[overrides]]
    files = ["*.groovy"]
    options = { parser = "groovy" }

    Another option could to look at npm-groovy-lint that has a format flag-,%2D%2Dformat,-Boolean).

    • Add support for npm-groovy-lint #1121
  5. bric3 commented on Dec 16, 2025

    @bric3
    bric3
    on Dec 16, 2025
    Contributor
    More actions

    Back to this code

    spotless/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java

    Lines 125 to 151 in 5743609

    /** Returns the FormatterStep (whose state will be calculated lazily). */
    public FormatterStep build() {
    var roundtrippableState = new EquoStep(formatterVersion, settingProperties, settingXml, FileSignature.promise(settingsFiles), JarState.promise(() -> {
    P2QueryResult query;
    try {
    if (cacheDirectory != null) {
    CacheLocations.override_p2data = cacheDirectory.toPath().resolve("dev/equo/p2-data").toFile();
    }
    query = createModelWithMirrors().query(P2ClientCache.PREFER_OFFLINE, P2QueryCache.ALLOW);
    } catch (Exception x) {
    throw new IOException("Failed to load " + formatterName + ": " + x, x);
    }
    var classpath = new ArrayList<File>();
    var mavenDeps = new ArrayList<String>();
    mavenDeps.add("dev.equo.ide:solstice:1.8.1");
    mavenDeps.add("com.diffplug.durian:durian-swt.os:4.3.1");
    mavenDeps.addAll(query.getJarsOnMavenCentral());
    classpath.addAll(mavenProvisioner.provisionWithTransitives(false, mavenDeps));
    classpath.addAll(query.getJarsNotOnMavenCentral());
    for (var nested : NestedJars.inFiles(query.getJarsNotOnMavenCentral()).extractAllNestedJars()) {
    classpath.add(nested.getValue());
    }
    return JarState.preserveOrder(classpath);
    }), stepProperties.build());
    return FormatterStep.create(formatterName, roundtrippableState, EquoStep::state, stateToFormatter);
    }

    At first I was thinking this code might need some caching, but upon further inspection, there's a design issue regarding how eclipse step are handled. The lambda is called as part of JarState.promise(...) and JarState.Promised#get does support caching, but it is called for each tasks.

    spotless/lib/src/main/java/com/diffplug/spotless/JarState.java

    Lines 72 to 83 in 5743609

    public JarState get() {
    try {
    if (cached == null) {
    JarState result = supplier.get();
    cached = result.fileSignature.asPromise();
    return result;
    }
    return new JarState(cached.get());
    } catch (Exception e) {
    throw ThrowingEx.asRuntime(e);
    }
    }

    The projects is configured with

    spotless {
      // only resolve the spotless dependencies once in the build
      predeclareDeps()
    }
    
    with(extensions["spotlessPredeclare"] as SpotlessExtension) {
      java {
        googleJavaFormat("1.32.0")
      }
      groovyGradle {
        greclipse()
      }
      groovy {
        greclipse()
      }
      ...
    }

    so the issue is that this JarState recomputes this for every tasks instead of doing it once.

    EquoBasedStepBuilder is created with a Provisioner that happens to be a GradleProvisioner.DedupingProvisioner when there's a predeclare. But this doesn't work with steps based on eclipse p2 via EquoBasedStepBuilder (steps like Eclipse CDT, Eclipse JDT, or GrEclipse), the reason is that the Provisioner only handle maven :

    spotless/lib/src/main/java/com/diffplug/spotless/Provisioner.java

    Lines 23 to 41 in 5743609

    /**
    * Many spotless steps require third-party libraries, but we want to keep
    * Spotless' dependencies minimal.
    */
    public interface Provisioner {
    /**
    * Given a set of Maven coordinates, returns a set of jars which include all
    * of the specified coordinates and optionally their transitive dependencies.
    */
    public default Set<File> provisionWithTransitives(boolean withTransitives, String... mavenCoordinates) {
    return provisionWithTransitives(withTransitives, Arrays.asList(mavenCoordinates));
    }
    /**
    * Given a set of Maven coordinates, returns a set of jars which include all
    * of the specified coordinates and optionally their transitive dependencies.
    */
    public Set<File> provisionWithTransitives(boolean withTransitives, Collection<String> mavenCoordinates);
    }

    As such, steps that require p2 are actually doing repetitive work each time a task needs to be serialized. Possibly to fix that issue, I see two good options, but not being the owner of the code I might have missed some other avenues:

    1. Make Provisioner handle p2 queries as well. This has consequences however on the SAMy use of this interface.
    2. Make a different provisioner for P2, that can be passed in Eclipse based steps.
  6. bric3 commented on Dec 16, 2025

    @bric3
    bric3
    on Dec 16, 2025
    Contributor
    More actions

    @nedtwigg @Goooler I'm ready to contribute (not sure when though with the end of year), but maybe you can chime in to weigh in which path to choose. Thanks in advance.

    Reacted by Vincent Potuček and Alexey Kuznetsov
    Reacted by Bruce Bujon
  7. bric3 commented on Jan 5, 2026

    @bric3
    bric3
    on Jan 5, 2026
    Contributor
    More actions

    @nedtwigg @Goooler Also, this looks like spotless lib issue, that will affect both maven and gradle project alike. Albeit, way worse on Gradle.

  8. bric3 commented on Jan 26, 2026

    @bric3
    bric3
    on Jan 26, 2026
    Contributor
    More actions

    I went ahead this week-end, as it's really painful to use spotless.
    See #2834

    Reacted by Alexey Kuznetsov
    Reacted by Alexey Kuznetsov and Mykola Nikishov
  9. nedtwigg
    closed this as completedin #2834on Jan 27, 2026
  10. bric3
    added 2 commits that reference this issue on Jan 28, 2026

    build: Bump spotless to 8.2.1

    b94a2c4

    build: Bump spotless to 8.2.1 (#10456)

    949e5f9
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.