Skip to content

Fix: importOrder() with single catch-all group strips blank lines added by greclipse(), causing non-idempotent formatting#2914

Merged
nedtwigg merged 3 commits intodiffplug:mainfrom
austek:fix/groovy_formatting
May 8, 2026
Merged

Fix: importOrder() with single catch-all group strips blank lines added by greclipse(), causing non-idempotent formatting#2914
nedtwigg merged 3 commits intodiffplug:mainfrom
austek:fix/groovy_formatting

Conversation

@austek
Copy link
Copy Markdown
Contributor

@austek austek commented May 1, 2026

Summary

  • importOrder() with no explicit groups (single catch-all) unconditionally replaced the entire import block, stripping any blank lines that a prior step like greclipse() had independently inserted between import groups.
  • This created an infinite cycle: greclipse() adds blank lines → importOrder() strips them → greclipse() re-adds them → repeat (GitHub issue Maven Groovy importOrder prevents greclipse from checking and applying #899).
  • Fix: when the sorted output contains no blank-line separators (single catch-all group) and the imports are already in the correct order, return the raw input unchanged, preserving any blank lines already present.

Test plan

  • groovyImportsPreservesBlankLinesBetweenGroups — asserts that importOrder() with no args leaves an already-sorted Groovy import block with blank lines untouched.
  • groovySortImportsStripsInterleavedBlankLines — asserts that sorting still works when imports are out of order; interleaved blank lines are removed as a side effect of the rewrite.

Fixes #899

austek added a commit to austek/spotless that referenced this pull request May 1, 2026
…plug#2914)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@austek austek force-pushed the fix/groovy_formatting branch from 28edf92 to 0c25202 Compare May 1, 2026 11:42
@austek
Copy link
Copy Markdown
Contributor Author

austek commented May 8, 2026

The build (gradle, 17, windows-latest) job on the latest run hung past the 6h timeout in the build (everything-but-maven) step. The same command passed on Windows JDK 21 (~15m) and JDK 24 (~14m), so this looks like a Windows/JDK 17 flake rather than a real failure. Could a maintainer rerun the failed job? Thanks! @nedtwigg

@nedtwigg nedtwigg merged commit 23c9341 into diffplug:main May 8, 2026
35 of 37 checks passed
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.

Maven Groovy importOrder prevents greclipse from checking and applying

2 participants