Skip to content

Commit 363f555

Browse files
authored
Limit name-based repo duplicate check to URL-less repositories (#7245)
The name-based fallback added in #7230 incorrectly blocks adding a second `maven {}` or `ivy {}` repository with a different URL, since it only checks the method name. Gate the check on `url == null` so it only applies to uniquely-named repositories like `gradlePluginPortal`, `mavenCentral`, `mavenLocal`, and `google`.
1 parent c7d548a commit 363f555

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

rewrite-gradle/src/main/java/org/openrewrite/gradle/plugins/AddSettingsPluginRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ private Statement addRepoToRepositoriesBlock(Statement statement, J pluginManage
197197
}
198198
J.MethodInvocation repoToAdd = extractRepository(pluginManagement);
199199

200-
if (repoAlreadyExists(repos, repoToAdd.getSimpleName())) {
200+
if (url == null && repoAlreadyExists(repos, repoToAdd.getSimpleName())) {
201201
return statement;
202202
}
203203

rewrite-gradle/src/test/java/org/openrewrite/gradle/plugins/AddSettingsPluginRepositoryTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,37 @@ void skipWhenExistsGradlePluginPortalWithOtherReposKtsWithoutTypeAttribution() {
642642
);
643643
}
644644

645+
@Test
646+
void addSecondMavenRepoKts() {
647+
rewriteRun(
648+
spec -> spec.recipe(new AddSettingsPluginRepository("maven", "https://repo.spring.io"))
649+
.expectedCyclesThatMakeChanges(1).cycles(3),
650+
settingsGradleKts(
651+
"""
652+
pluginManagement {
653+
repositories {
654+
maven {
655+
url = uri("https://repo.example.com/releases")
656+
}
657+
}
658+
}
659+
""",
660+
"""
661+
pluginManagement {
662+
repositories {
663+
maven {
664+
url = uri("https://repo.example.com/releases")
665+
}
666+
maven {
667+
url = uri("https://repo.spring.io")
668+
}
669+
}
670+
}
671+
"""
672+
)
673+
);
674+
}
675+
645676
@Test
646677
void addToExistingPluginManagementWithPluginsBlockKts() {
647678
rewriteRun(

0 commit comments

Comments
 (0)