Support programmed Gradle Version Catalogs version upgrades - #8503
Open
BoykoAlex wants to merge 2 commits into
Open
Support programmed Gradle Version Catalogs version upgrades#8503BoykoAlex wants to merge 2 commits into
BoykoAlex wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What's changed?
Adds Gradle Version Catalog support (
dependencyResolutionManagement { versionCatalogs { ... } } }, both Groovy and Kotlin DSL) toUpgradeDependencyVersion, so it can bump versions declared in a catalog instead of only versions declared directly inbuild.gradle/build.gradle.ktsdependency blocks.Scope for this PR is intentionally limited to
library(...)andversion(...)declarations. Catalogplugin(...)andbundle(...)entries, andfrom(...)(TOML-file-backed catalogs), are not supported yet.This is implemented via three new traits:
GradleVersionCatalog— represents a single named catalog (libs { ... }/create("libs") { ... }), exposing its libraries and version declarations, and applying version changes to them.VersionCatalogLibrary— a singlelibrary(...)declaration, with its inline version,versionRef(...), orwithoutVersion()form.VersionCatalogVersion— a singleversion(alias, value)declaration.Several libraries commonly share one
version(...)declaration viaversionRef(...)(e.g. a dozenspring-boot-starter-*artifacts all pointing at onespringBootversion).UpgradeDependencyVersionnow handles this correctly:version(...)declaration itself is bumped once.withoutVersion(), a rich.version { strictly(...) } }constraint, or an interpolated"${...}"string -- is treated consistently: left unchanged rather than crashing or being forced to a literal, and it doesn't interfere with reconciliation of any group it isn't genuinely part of.A new
GradleVersionCatalogVersionReferencesmarker snapshots the original versionRef sharing structure the first time a catalog is touched, so the detach/re-attach algorithm above can tell whether two separately-requested bumps actually target the same underlying declaration.Also adds a few small reusable helpers to
GradleTraitMatcher(isTopLevelStatement,asChainedInvocation,literalArgument) used by the new traits.What's your motivation?
Gradle Version Catalogs are the recommended way to declare dependency versions in modern Gradle projects, but
UpgradeDependencyVersionpreviously had no awareness of them, so catalog-based projects couldn't be upgraded automatically.Anything in particular you'd like reviewers to focus on?
GradleVersionCatalog(withVersion,withOriginalVersionReferencesMarker,reconciledAfterDetaching) — this is the trickiest part of the change and is deliberately kept separate fromUpgradeDependencyVersion's existingsafeUpdatedVersionlogic for Gradle variables, since the two cases have different sharing semantics.GradleVersionCatalog(AST walk cached per-instance, discarded on any mutation) is an acceptable tradeoff.Have you considered any alternatives or workarounds?
Considered forcing
withoutVersion()libraries onto the target version whenever one is specified, but decided against special-casing it: it's just one of several shapes (alongside rich.version { ... }constraints and interpolated versions) where a library's version can't be resolved to a literal, and all of them are now handled the same way -- left unchanged rather than crashing.Checklist
./gradlew buildlocally