Fix AddSettingsPluginRepository duplicate pluginManagement and repository handling#6959
Merged
Fix AddSettingsPluginRepository duplicate pluginManagement and repository handling#6959
AddSettingsPluginRepository duplicate pluginManagement and repository handling#6959Conversation
Extract `repositoryExists` method for clarity. Handle `J.Return`-wrapped
`pluginManagement` statements in `addPluginManagementRepos`, which can
occur in Kotlin settings files where the last expression is wrapped in
a return node.
Add comprehensive test coverage for `gradlePluginPortal` and `mavenLocal`
repository types with skip-when-exists, idempotency, and complex settings
file scenarios for both Groovy and Kotlin DSL.
Fixes moderneinc/customer-requests#1986
a5bd6c6 to
3cdb827
Compare
AddSettingsPluginRepository duplicate pluginManagement and repository handling
MBoegers
approved these changes
Mar 12, 2026
Contributor
MBoegers
left a comment
There was a problem hiding this comment.
I retuced the number of tests as there where a lot of duplicates.
...ite-gradle/src/test/java/org/openrewrite/gradle/plugins/AddSettingsPluginRepositoryTest.java
Outdated
Show resolved
Hide resolved
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
AddSettingsPluginRepositoryto correctly detect existingpluginManagementblocks wrapped inJ.Return(Kotlin settings files)gradlePluginPortal,mavenLocal)Problem
The
AddSettingsPluginRepositoryrecipe has two bugs:gradlePluginPortal()when already present)pluginManagementblockThe root cause is that
addPluginManagementRepos()only checked forJ.MethodInvocationas the first statement, but in Kotlin settings files the parser wraps the last expression inJ.Return, so the existingpluginManagementblock was not recognized and a duplicate was inserted.Solution
J.Returnunwrapping when detecting existingpluginManagementblocks inaddPluginManagementRepos()pluginManagement, re-wraps inJ.Returnif the original was wrappedgradlePluginPortal/mavenLocal(Groovy+KTS), no-duplicate-pluginManagement-block scenarios, idempotency (3 cycles), complex settings files, and adding repos to existing blocksTest plan
All 20 new tests pass
All existing tests pass
Idempotency verified with 3-cycle tests
Fixes moderneinc/customer-requests#1986