Skip to content

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

@mkutz

Description

@mkutz

I'd like to have a layout step that formates and also sorts TOML files.

  • proper spacing around special characters
    E.g. kotlin-jvm={id="org.jetbrains.kotlin.jvm",version="2.3.21"}kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version = "2.3.21" } or assertj="3.27.7"assertj = "3.27.7"
  • line breaks for long definitions
  • sort standard version catalog tables:
    1. [versions]
    2. [libraries]
    3. [bundles]
    4. [plugins]
  • sort table entries alphabetically simply by line, hence the chose alias will determine the order

Example

Unformatted:

[versions]
assertj="3.27.7"
testcontainers= "2.0.5"
junit ="6.0.3"

[libraries]
junit-bom = { module = "org.junit:junit-bom", version.ref = "junit" }
junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api" }
junit-jupiter-engine = {module = "org.junit.jupiter:junit-jupiter-engine"}
junit-jupiter-params = { module = "org.junit.jupiter:junit-jupiter-params" }
junit-platform-launcher = { module = "org.junit.platform:junit-platform-launcher" }
assertj-core = { module = "org.assertj:assertj-core", version.ref="assertj" }
testcontainers-junit-jupiter= { module = "org.testcontainers:testcontainers-junit-jupiter", version.ref = "testcontainers" }
testcontainers-postgresql ={ module = "org.testcontainers:testcontainers-postgresql", version.ref = "testcontainers" }

[plugins]
sonar = { id = "org.sonarqube", version= "7.3.0.8198" }
spotless = { id = "com.diffplug.spotless", version= "7.2.1" }
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version = "2.3.21" }

[bundles]
junit = ["junit-jupiter-api","junit-jupiter-params"]

Formatted:

[versions]
assertj = "3.27.7"
junit = "6.0.3"
testcontainers = "2.0.5"

[libraries]
assertj-core = { module = "org.assertj:assertj-core", version.ref = "assertj" }
junit-bom = { module = "org.junit:junit-bom", version.ref = "junit" }
junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api" }
junit-jupiter-engine = { module = "org.junit.jupiter:junit-jupiter-engine" }
junit-jupiter-params = { module = "org.junit.jupiter:junit-jupiter-params" }
junit-platform-launcher = { module = "org.junit.platform:junit-platform-launcher" }
testcontainers-junit-jupiter = { module = "org.testcontainers:testcontainers-junit-jupiter", version.ref = "testcontainers" }
testcontainers-postgresql = { module = "org.testcontainers:testcontainers-postgresql", version.ref = "testcontainers" }

[bundles]
junit = [ "junit-jupiter-api", "junit-jupiter-params" ]

[plugins]
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version = "2.3.21" }
sonar = { id = "org.sonarqube", version = "7.3.0.8198" }
spotless = { id = "com.diffplug.spotless", version = "7.2.1" }

I'd be happy to provide a PR for this. I already have a general proof of concept implemented as a custom step... needs some more work, though.

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