Skip to content

Commit b8612b5

Browse files
authored
Skip BOM download when version contains unresolved placeholders (#6674)
* Add failing test for mavenBom with unresolved Gradle variable Reproduces IllegalArgumentException when RemoveRedundantDependencyVersions encounters a mavenBom dependency that uses a Gradle variable reference like ${springCloudVersion}. The unresolved placeholder is passed to MavenPomDownloader.download() which fails in URI.create(). * Skip BOM download when version contains unresolved placeholders When a mavenBom entry in the Spring dependency-management plugin uses a Gradle variable (e.g. ${springCloudVersion}), the version is stored as a literal placeholder string. Passing this to MavenPomDownloader.download() causes IllegalArgumentException from URI.create() because ${ is not valid in a URI path. Skip the download attempt when the version contains unresolved ${} placeholders, consistent with how the recipe already handles missing versions.
1 parent f969eac commit b8612b5

2 files changed

Lines changed: 66 additions & 1 deletion

File tree

rewrite-gradle/src/main/java/org/openrewrite/gradle/RemoveRedundantDependencyVersions.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,13 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
155155
J.MethodInvocation m = super.visitMethodInvocation(method, ctx);
156156
new SpringDependencyManagementPluginEntry.Matcher().get(getCursor()).ifPresent(entry -> entry.getArtifacts().forEach(artifact -> {
157157
if ("mavenBom".equals(method.getSimpleName())) {
158+
String version = entry.getVersion();
159+
if (version == null || version.contains("${")) {
160+
return;
161+
}
158162
MavenPomDownloader mpd = new MavenPomDownloader(ctx);
159163
try {
160-
ResolvedPom platformPom = mpd.download(new GroupArtifactVersion(entry.getGroup(), artifact, entry.getVersion()), null, null, gp.getMavenRepositories())
164+
ResolvedPom platformPom = mpd.download(new GroupArtifactVersion(entry.getGroup(), artifact, version), null, null, gp.getMavenRepositories())
161165
.resolve(emptyList(), mpd, ctx);
162166
platformPom.getDependencyManagement().stream()
163167
.filter(managedVersion -> managedVersion.getVersion() != null)

rewrite-gradle/src/test/java/org/openrewrite/gradle/RemoveRedundantDependencyVersionsTest.java

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,4 +1017,65 @@ void webfluxGTE() {
10171017
)
10181018
);
10191019
}
1020+
1021+
@Test
1022+
void mavenBomWithUnresolvedVariable() {
1023+
rewriteRun(
1024+
spec -> spec.recipe(new RemoveRedundantDependencyVersions(null, null, RemoveRedundantDependencyVersions.Comparator.GTE)),
1025+
buildGradle(
1026+
"""
1027+
plugins {
1028+
id "java"
1029+
id("org.springframework.boot") version "3.5.6"
1030+
id("io.spring.dependency-management") version "1.1.7"
1031+
}
1032+
1033+
ext {
1034+
springCloudVersion = '2024.0.1'
1035+
}
1036+
1037+
repositories {
1038+
mavenCentral()
1039+
}
1040+
1041+
dependencyManagement {
1042+
imports {
1043+
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
1044+
}
1045+
}
1046+
1047+
dependencies {
1048+
implementation('org.springframework.boot:spring-boot')
1049+
implementation("org.apache.commons:commons-lang3:3.14.0")
1050+
}
1051+
""",
1052+
"""
1053+
plugins {
1054+
id "java"
1055+
id("org.springframework.boot") version "3.5.6"
1056+
id("io.spring.dependency-management") version "1.1.7"
1057+
}
1058+
1059+
ext {
1060+
springCloudVersion = '2024.0.1'
1061+
}
1062+
1063+
repositories {
1064+
mavenCentral()
1065+
}
1066+
1067+
dependencyManagement {
1068+
imports {
1069+
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
1070+
}
1071+
}
1072+
1073+
dependencies {
1074+
implementation('org.springframework.boot:spring-boot')
1075+
implementation("org.apache.commons:commons-lang3")
1076+
}
1077+
"""
1078+
)
1079+
);
1080+
}
10201081
}

0 commit comments

Comments
 (0)