Skip to content

Commit 9a6f7a5

Browse files
gnodetclaude
andcommitted
Filter project repositories with uninterpolated property expressions (PR #12204)
Cherry-pick from fix/filter-unresolvable-project-repos branch. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent ede1670 commit 9a6f7a5

5 files changed

Lines changed: 38 additions & 31 deletions

File tree

impl/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingHelper.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ public List<ArtifactRepository> createArtifactRepositories(
9292
List<ArtifactRepository> internalRepositories = new ArrayList<>();
9393

9494
for (Repository repository : pomRepositories) {
95+
if (containsExpression(repository.getId()) || containsExpression(repository.getUrl())) {
96+
logger.warn(
97+
"Skipping repository '{}' (url: '{}') containing an uninterpolated property expression",
98+
repository.getId(),
99+
repository.getUrl());
100+
continue;
101+
}
95102
internalRepositories.add(MavenRepositorySystem.buildArtifactRepository(repository));
96103
}
97104

@@ -267,6 +274,10 @@ public void selectProjectRealm(MavenProject project) {
267274
Thread.currentThread().setContextClassLoader(projectRealm);
268275
}
269276

277+
private static boolean containsExpression(String value) {
278+
return value != null && value.contains("${");
279+
}
280+
270281
private List<org.eclipse.aether.artifact.Artifact> toAetherArtifacts(final List<Artifact> pluginArtifacts) {
271282
return new ArrayList<>(RepositoryUtils.toArtifacts(pluginArtifacts));
272283
}

impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelValidator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,11 +1535,11 @@ private void validateRawRepository(
15351535
if (matcher.find()) {
15361536
addViolation(
15371537
problems,
1538-
Severity.ERROR,
1538+
Severity.WARNING,
15391539
Version.V40,
15401540
prefix + prefix2 + "[" + repository.getId() + "].id",
15411541
null,
1542-
"contains an uninterpolated expression.",
1542+
"contains an uninterpolated expression; the repository will be skipped.",
15431543
repository);
15441544
}
15451545
}
@@ -1561,11 +1561,11 @@ && validateStringNotEmpty(
15611561
if (matcher.find()) {
15621562
addViolation(
15631563
problems,
1564-
Severity.ERROR,
1564+
Severity.WARNING,
15651565
Version.V40,
15661566
prefix + prefix2 + "[" + repository.getId() + "].url",
15671567
null,
1568-
"contains an uninterpolated expression.",
1568+
"contains an uninterpolated expression; the repository will be skipped.",
15691569
repository);
15701570
}
15711571
}

impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultModelValidatorTest.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -907,31 +907,33 @@ void repositoryWithBasedirExpression() throws Exception {
907907
SimpleProblemCollector result = validateRaw("raw-model/repository-with-basedir-expression.xml");
908908
// This test runs on raw model without interpolation, so all expressions appear uninterpolated
909909
// In the real flow, supported expressions would be interpolated before validation
910-
assertViolations(result, 0, 3, 0);
910+
assertViolations(result, 0, 0, 3);
911911
}
912912

913913
@Test
914914
void repositoryWithUnsupportedExpression() throws Exception {
915915
SimpleProblemCollector result = validateRaw("raw-model/repository-with-unsupported-expression.xml");
916-
// Unsupported expressions should cause validation errors
917-
assertViolations(result, 0, 1, 0);
916+
// Unsupported expressions should cause validation warnings (repos will be skipped at build time)
917+
assertViolations(result, 0, 0, 1);
918918
}
919919

920920
@Test
921921
void repositoryWithUninterpolatedId() throws Exception {
922922
SimpleProblemCollector result = validateRaw("raw-model/repository-with-uninterpolated-id.xml");
923-
// Uninterpolated expressions in repository IDs should cause validation errors
923+
// Uninterpolated expressions in repository IDs should cause validation warnings
924+
// (repos will be skipped at build time)
924925
// distributionManagement repositories skip expression check since parent properties
925926
// may not be available at file model validation stage
926-
assertViolations(result, 0, 2, 0);
927+
assertViolations(result, 0, 0, 2);
927928

928-
// Check that repository ID validation errors are present for repositories and pluginRepositories
929-
assertTrue(result.getErrors().stream()
930-
.anyMatch(error -> error.contains("repositories.repository.[${repository.id}].id")
931-
&& error.contains("contains an uninterpolated expression")));
932-
assertTrue(result.getErrors().stream()
933-
.anyMatch(error -> error.contains("pluginRepositories.pluginRepository.[${plugin.repository.id}].id")
934-
&& error.contains("contains an uninterpolated expression")));
929+
// Check that repository ID validation warnings are present for repositories and pluginRepositories
930+
assertTrue(result.getWarnings().stream()
931+
.anyMatch(warning -> warning.contains("repositories.repository.[${repository.id}].id")
932+
&& warning.contains("contains an uninterpolated expression")));
933+
assertTrue(result.getWarnings().stream()
934+
.anyMatch(
935+
warning -> warning.contains("pluginRepositories.pluginRepository.[${plugin.repository.id}].id")
936+
&& warning.contains("contains an uninterpolated expression")));
935937
}
936938

937939
@Test

its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh11140RepoDmUnresolvedTest.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,14 @@ class MavenITgh11140RepoDmUnresolvedTest extends AbstractMavenIntegrationTestCas
3232
}
3333

3434
@Test
35-
void testFailsOnUnresolvedPlaceholders() throws Exception {
35+
void testWarnsOnUnresolvedPlaceholders() throws Exception {
3636
File testDir = extractResources("/gh-11140-repo-dm-unresolved");
3737
Verifier verifier = newVerifier(testDir.getAbsolutePath());
3838

39-
try {
40-
verifier.addCliArgument("validate");
41-
verifier.execute();
42-
} catch (VerificationException expected) {
43-
// Expected to fail due to unresolved placeholders during model validation
44-
}
45-
// We expect error mentioning uninterpolated expression
39+
verifier.addCliArgument("validate");
40+
verifier.execute();
41+
// Build should succeed, but warn about uninterpolated expressions (repos are skipped)
42+
verifier.verifyErrorFreeLog();
4643
verifier.verifyTextInLog("contains an uninterpolated expression");
4744
}
4845
}

its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh11140RepoInterpolationTest.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,15 @@ private static String getBaseUri(Path base) {
7373
}
7474

7575
@Test
76-
void testUnresolvedPlaceholderFailsResolution() throws Exception {
76+
void testUnresolvedPlaceholderWarnsAndSkipsRepository() throws Exception {
7777
File testDir = extractResources("/gh-11140-repo-interpolation");
7878
Verifier verifier = newVerifier(testDir.getAbsolutePath());
7979

8080
// Do NOT set env vars, so placeholders stay
8181
verifier.addCliArgument("validate");
82-
try {
83-
verifier.execute();
84-
} catch (VerificationException expected) {
85-
// Expected to fail due to unresolved placeholders during model validation
86-
}
87-
// We expect error mentioning uninterpolated expression
82+
verifier.execute();
83+
// Build should succeed, but warn about uninterpolated expressions
84+
verifier.verifyErrorFreeLog();
8885
verifier.verifyTextInLog("contains an uninterpolated expression");
8986
}
9087
}

0 commit comments

Comments
 (0)