Add OneDependencyDeclarationPerStatement recipe to the Gradle 9 chain#7907
Open
Jenson3210 wants to merge 2 commits into
Open
Add OneDependencyDeclarationPerStatement recipe to the Gradle 9 chain#7907Jenson3210 wants to merge 2 commits into
OneDependencyDeclarationPerStatement recipe to the Gradle 9 chain#7907Jenson3210 wants to merge 2 commits into
Conversation
`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.
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.
Summary
org.openrewrite.gradle.gradle9.OneDependencyDeclarationPerStatementsplits multi-coordinate Groovy DSL configuration calls into one call per coordinate (e.g.implementation 'a:b:1.0', 'c:d:2.0'→ twoimplementationstatements).MigrateToGradle9chain (so it also flows intoGradleBestPractices).@Disabledmarker test inUpgradeDependencyVersionTestis 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, andRemoveDependencyall rely on theGradleDependencytrait, 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.Behavior notes
G.CompilationUnit-gated; Kotlin DSL files are left untouched (Kotlin can't express the input).implementation('a:b:1.0') { exclude … }), and the multi-component positional form (implementation 'group', 'name', 'version').Test plan
:rewrite-gradle:test --tests "*OneDependencyDeclarationPerStatementTest"— 8 tests, all green (@DocumentExamplebasic split, version-variable second coord, multi-config blocks, comment preservation, and three no-op cases).:rewrite-gradle:test— no regressions.recipes.csvregenerated via./gradlew :rewrite-gradle:recipeCsvGenerate.