Skip to content

4400 - gradle toml version catalogs - #8274

Open
KamilPatora wants to merge 30 commits into
openrewrite:mainfrom
KamilPatora:4400-gradle-toml-version-catalogs
Open

4400 - gradle toml version catalogs#8274
KamilPatora wants to merge 30 commits into
openrewrite:mainfrom
KamilPatora:4400-gradle-toml-version-catalogs

Conversation

@KamilPatora

@KamilPatora KamilPatora commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds Gradle Version Catalog support to the following recipes:

  • ChangeDependency
  • UpgradeDependencyVersion
  • UpgradePluginVersion

The recipes can now recognize and update dependencies and plugins declared in the conventional gradle/libs.versions.toml catalog in addition to declarations in Gradle build scripts.

Implementation

This PR introduces semantic traits for Gradle Version Catalogs instead of embedding TOML-specific logic into individual recipes.

New traits include:

  • GradleVersionCatalog
  • GradleVersionCatalogDependency
  • GradleVersionCatalogPlugin

These traits model version catalog entries as dependencies and plugins, allowing existing Gradle recipes to operate on them using the same high-level concepts they already use for Gradle source files.

The implementation supports:

  • Direct versions (version = "...")
  • Shared version references (version.ref)
  • Inline table notation
  • Compact string notation (group:artifact[:version])
  • module = "group:artifact" notation
  • Plugin declarations

Shared version.ref entries are updated conservatively. A referenced version is modified only when every consumer of that reference is supported by the recipe and resolves to the same replacement version, preventing unintended changes to unrelated catalog entries.

Supported Scope

This PR supports the conventional Gradle version catalog located at gradle/libs.versions.toml.

Supported library declarations include:

  • group / name notation
  • module notation
  • Compact string notation
  • Direct versions
  • version.ref

Supported plugin declarations include:

  • Direct versions
  • version.ref

Out of Scope

The following are intentionally not supported in this PR:

  • Rich version declarations (for example strictly, prefer, reject, and require)
  • Custom or named version catalogs
  • Bundle mutation
  • GradleProject model synchronization after catalog-only changes

When an unsupported version declaration is encountered during a requested version change, the catalog entry is left unchanged rather than partially updating only its coordinates.

Tests

The test suite covers:

  • Direct version updates
  • version.ref updates
  • Shared version.ref coordination
  • Inline table notation
  • Compact string notation
  • module notation
  • Plugin version updates
  • Coordinate relocation
  • overrideManagedVersion behavior
  • Unsupported version declarations remaining unchanged
  • Gradle Kotlin DSL projects using version catalogs

@timtebeek

Copy link
Copy Markdown
Member

Thanks for kicking this off @KamilPatora ! I'd have perhaps expected more of these changes to land in the Gradle dependency trait we added a while back, but I'm not sure how far we've gotten with adoption there:

My aim with the trait would be to limit which recipes even need to know about Toml specifically; ideally that's all handled by the trait and recipes just concern themselves with the question of bumping a version based on what's encountered. Perhaps @shanman190 has additional thoughts here as well. It's definitely a larger topic, but worth exploring to reduce complexity across recipes.

@KamilPatora
KamilPatora marked this pull request as draft July 17, 2026 15:40
…ted Gradle version catalog traits, keeping recipe logic focused on selecting replacement versions. Centralize shared version.ref updates
@KamilPatora

KamilPatora commented Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback! I’ve only been working with TOML files for about a month, so I’m still getting a feel for how this should fit into the existing GradleDependency trait. Any ideas or guidance would be super welcome.

For now, I kept the TOML stuff in separate catalog traits since it’s a different AST model from build scripts.
Does that seem like the right direction @timtebeek?

@KamilPatora
KamilPatora marked this pull request as ready for review July 17, 2026 16:46
@timtebeek

Copy link
Copy Markdown
Member

Apologies for the slow response here! In the case of Gradle and Toml I don't have all the answers, and with other work I've not found the time to dive in yet.

@KamilPatora

Copy link
Copy Markdown
Contributor Author

Hey @timtebeek. Done some improvements here and there. I think this looks better than before... lol

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

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

2 participants