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) #2788DescriptionFollow-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:
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 Activitybric3 commented on Dec 11, 2025 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

CPU

Monitor Blocked

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. bric3 commented on Dec 11, 2025 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.
We can also see that, this behavior happens for the whole life time of Execution Worker threads. bric3 commented on Dec 11, 2025 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.
Unfortunately this lazy computation of the state, has terrible performance impact. Reacted by Vincent Potuček bric3 commented on Dec 12, 2025 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).
bric3 commented on Dec 16, 2025 Back to this code
|
/** 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.
|
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 :
|
/** |
|
* 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:
- Make
Provisioner handle p2 queries as well. This has consequences however on the SAMy use of this interface.
- Make a different provisioner for P2, that can be passed in Eclipse based steps.
bric3 commented on Dec 16, 2025 @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 bric3 commented on Jan 5, 2026 @nedtwigg @Goooler Also, this looks like spotless lib issue, that will affect both maven and gradle project alike. Albeit, way worse on Gradle. bric3 commented on Jan 26, 2026 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
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|