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 — Add TOML version catalog formatter step by mkutz · Pull Request #2917 · diffplug/spotless

Conversation

@mkutz

@mkutz mkutz commented May 4, 2026

Copy link
Copy Markdown

Resolves #2916

Adds a dedicated FormatterStep for formatting and sorting Gradle version catalog (.toml) files, with no external dependencies.

Features

  • Normalize spacing around = and inside inline tables { } and arrays [ ]
  • Sort entries alphabetically within each section
  • Sort sections in canonical order: [versions], [libraries], [bundles], [plugins]
  • Preserve comments — leading comments travel with their entry during sorting; inline comments are preserved
  • Multi-line inline tables — parsed correctly and joined/split based on line length
  • maxLineLength (default 120, configurable) — long inline tables are split across lines (one pair per line, 2-space indent, trailing commas)
  • stripQuotedKeys (opt-in, default false) — removes unnecessary quotes from keys when the bare form is valid

Usage

Gradle:

spotless {
  toml {
    target 'gradle/libs.versions.toml'
    versionCatalog()
    // or with options:
    // versionCatalog { maxLineLength(80); stripQuotedKeys(true) }
  }
}

Maven:

<toml>
  <includes>
    <include>gradle/libs.versions.toml</include>
  </includes>
  <versionCatalog />
</toml>

Known limitations

Documented in lib/src/main/java/com/diffplug/spotless/toml/TODO.md. These are valid TOML constructs that won't appear in typical Gradle version catalogs:

  • Quoted keys containing =
  • Dotted/quoted table headers
  • Single-quoted (literal) strings in inline tables
  • Triple-quoted multiline strings

Checklist

  • Class name ends in Step (VersionCatalogStep)
  • Public static create method returning FormatterStep
  • Test class VersionCatalogStepTest using StepHarness
  • Equality test using SerializableEqualityTester
  • Changelog entries in all three CHANGES.md files
  • spotlessApply clean
  • spotbugsMain clean

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Michael Kutz added 5 commits May 4, 2026 10:08
Michael Kutz
Add TOML version catalog formatter step (diffplug#2916)
f57a102
Add a dedicated FormatterStep for formatting and sorting Gradle version
catalog files (libs.versions.toml). The step normalizes spacing around
operators and inside inline tables/arrays, sorts entries alphabetically,
and orders tables canonically ([versions], [libraries], [bundles], [plugins]).
Michael Kutz
Fix comment handling, inline comments, preamble, and sort order
a405e7a
- Preserve comments inside sections by attaching them to the entry
  below, so they travel with the entry during sorting
- Strip and re-attach inline comments (# ...) before formatting
  inline tables/arrays
- Preserve blank lines in the file preamble
- Sort entries by logical key name, stripping surrounding quotes
- Add TODO.md documenting remaining TOML spec edge cases
Michael Kutz
Add opt-in stripQuotedKeys option for version catalog step
2992ff5
Adds a stripQuotedKeys parameter (default false) that removes unnecessary
quotes from keys when the unquoted form is a valid bare TOML key. Keys
like "foo.bar" that would change semantics are preserved.
Michael Kutz
Handle multi-line inline tables and add maxLineLength option
c9fb959
- Parse multi-line inline tables by tracking brace/bracket depth and
  joining continuation lines into a single entry
- Add configurable maxLineLength (default 120): lines exceeding the
  limit split their inline table across multiple lines (one pair per
  line, 2-space indent, trailing commas); multi-line tables that fit
  are joined into a single line
- Update TODO.md with fixed items
Michael Kutz
Add changelog entries for TOML version catalog step
35356db
@nedtwigg
nedtwigg merged commit c8e8ade into diffplug:main May 14, 2026
20 checks passed

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

TOML: dedicated plugin to format and sort libs.versions.toml files in Gradle projects

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@mkutz @nedtwigg
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.