Commit 18e5bb7
Fix duplicate gradlePluginPortal() in settings.gradle.kts (#7230)
* Add failing tests for duplicate gradlePluginPortal() in KTS with wrong type attribution
When method types have an incorrect declaring type (as happens on the
platform with KTS-parsed settings.gradle.kts), FindRepository's
MethodMatcher fails to detect existing repositories, causing
AddSettingsPluginRepository to add duplicates.
Reproduces moderneinc/customer-requests#2120
* Fix duplicate gradlePluginPortal() in settings.gradle.kts with incorrect type attribution
On the Moderne platform, KTS-parsed settings.gradle.kts files may have
incorrect type attribution on method invocations (e.g. wrong declaring
type instead of RepositoryHandler). This causes FindRepository's
MethodMatcher to fail the strict matching path, missing existing
repository entries and leading AddSettingsPluginRepository to add
duplicates.
Added two defensive checks:
1. In addRepoToRepositoriesBlock: name-based check if the repository
already exists in the repositories block before adding
2. In addPluginManagementRepos: detect when pluginManagement exists but
no change was needed, to avoid inserting a duplicate block
Fixes moderneinc/customer-requests#2120
* Clarify comment: workaround for Kotlin parser type attribution issue
* Consolidate comment on repoAlreadyExists method
---------
Co-authored-by: Jente Sondervorst <jentesondervorst@gmail.com>1 parent 5b212d9 commit 18e5bb7
File tree
2 files changed
+86
-0
lines changed- rewrite-gradle/src
- main/java/org/openrewrite/gradle/plugins
- test/java/org/openrewrite/gradle/plugins
2 files changed
+86
-0
lines changedLines changed: 28 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
138 | 138 | | |
139 | 139 | | |
140 | 140 | | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
141 | 147 | | |
142 | 148 | | |
143 | 149 | | |
| |||
190 | 196 | | |
191 | 197 | | |
192 | 198 | | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
193 | 204 | | |
194 | 205 | | |
195 | 206 | | |
| |||
208 | 219 | | |
209 | 220 | | |
210 | 221 | | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
211 | 239 | | |
212 | 240 | | |
213 | 241 | | |
| |||
Lines changed: 58 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
20 | 24 | | |
21 | 25 | | |
22 | 26 | | |
| |||
584 | 588 | | |
585 | 589 | | |
586 | 590 | | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
587 | 645 | | |
588 | 646 | | |
589 | 647 | | |
| |||
0 commit comments