Skip to content

Add OneDependencyDeclarationPerStatement recipe to the Gradle 9 chain#7907

Open
Jenson3210 wants to merge 2 commits into
mainfrom
Jenson3210/check-usecase-6-support
Open

Add OneDependencyDeclarationPerStatement recipe to the Gradle 9 chain#7907
Jenson3210 wants to merge 2 commits into
mainfrom
Jenson3210/check-usecase-6-support

Conversation

@Jenson3210
Copy link
Copy Markdown
Contributor

@Jenson3210 Jenson3210 commented Jun 5, 2026

Summary

  • New recipe org.openrewrite.gradle.gradle9.OneDependencyDeclarationPerStatement splits multi-coordinate Groovy DSL configuration calls into one call per coordinate (e.g. implementation 'a:b:1.0', 'c:d:2.0' → two implementation statements).
  • Wired into the MigrateToGradle9 chain (so it also flows into GradleBestPractices).
  • The previously committed @Disabled marker test in UpgradeDependencyVersionTest is removed; the deeper trait gap it documented continues to be tracked in moderneinc/customer-requests#2464.

Why

The multi-coordinate-per-call form is Groovy-DSL-only — Kotlin DSL forbids it — and Gradle's dependency best practices recommend declaring one dependency per statement. It also unblocks other dependency-aware recipes: UpgradeDependencyVersion, ChangeDependency, and RemoveDependency all rely on the GradleDependency trait, which only inspects the first argument of a configuration call. Coordinates in later positions are invisible to those recipes until this cleanup pass reshapes the source.

  • Surfaced via TIAA migration cases — see moderneinc/customer-requests#2462 (use case 6) and the spun-off engineering issue moderneinc/customer-requests#2464 for the broader trait refactor.

Behavior notes

  • Groovy DSL only — G.CompilationUnit-gated; Kotlin DSL files are left untouched (Kotlin can't express the input).
  • Skips: single-coordinate calls, calls ending in a configuration closure (implementation('a:b:1.0') { exclude … }), and the multi-component positional form (implementation 'group', 'name', 'version').
  • A statement-level line/block comment on the original multi-coordinate call is preserved on the first new statement only — not duplicated onto subsequent splits or the trailing implicit-return.

Test plan

  • :rewrite-gradle:test --tests "*OneDependencyDeclarationPerStatementTest" — 8 tests, all green (@DocumentExample basic split, version-variable second coord, multi-config blocks, comment preservation, and three no-op cases).
  • Full :rewrite-gradle:test — no regressions.
  • recipes.csv regenerated via ./gradlew :rewrite-gradle:recipeCsvGenerate.

`GradleDependency.Matcher#test` only inspects `arguments.get(0)`, so a
dependency declared as a later coordinate in a single configuration call
(e.g. `implementation 'a:b:1.0', 'c:d:' + version`) is invisible to the
trait and its `ext` version variable is never bumped.

See moderneinc/customer-requests#2464.
Splits multi-coordinate Groovy DSL configuration calls into one call per
coordinate (e.g. `implementation 'a:b:1.0', 'c:d:2.0'` becomes two
`implementation` statements). The form is Groovy-DSL-only — Kotlin DSL
forbids it — and Gradle's best practices recommend one dependency per
statement.

Documented as a cleanup pass to run before dependency-aware recipes
(`UpgradeDependencyVersion`, `ChangeDependency`, `RemoveDependency`):
those recipes use the `GradleDependency` trait, which only inspects the
first argument of a configuration call, so coordinates in later positions
are invisible until this recipe reshapes the source.

Wired into the `MigrateToGradle9` chain. Preserves any statement-level
comment on the first new statement only — not duplicated onto later
splits or the trailing implicit-return. The previously committed
`@Disabled` marker test for the underlying trait gap is removed; the
deeper trait refactor remains tracked in moderneinc/customer-requests#2464.
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.

1 participant