From 7595bdd6bca3edf83dcfeb49e824e9f9eac52bc4 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Mon, 18 May 2026 13:10:22 +0200 Subject: [PATCH] Fix #12075: skip expression validation for distributionManagement repository IDs Parent POM properties are not available during file model validation, so chained property references in distributionManagement repository IDs (e.g. ${distMgmtStagingId} -> ${distMgmtReleasesId}) cannot be fully resolved at this stage. Skip the uninterpolated expression check for distributionManagement repositories, consistent with how profile repositories are already handled. Uninterpolated repositories are still caught by MavenValidator when they are actually used by the resolver. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../impl/model/DefaultModelValidator.java | 4 +- .../impl/model/DefaultModelValidatorTest.java | 15 ++++-- .../dm-with-chained-property-in-id.xml | 46 +++++++++++++++++++ 3 files changed, 58 insertions(+), 7 deletions(-) create mode 100644 impl/maven-impl/src/test/resources/poms/validation/raw-model/dm-with-chained-property-in-id.xml diff --git a/impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelValidator.java b/impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelValidator.java index 79840fd52a11..37db33b4e465 100644 --- a/impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelValidator.java +++ b/impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelValidator.java @@ -647,14 +647,14 @@ public void validateRawModel(Session s, Model m, int validationLevel, ModelProbl DistributionManagement distMgmt = m.getDistributionManagement(); if (distMgmt != null) { validateRawRepository( - problems, distMgmt.getRepository(), "distributionManagement.repository.", "", true, false); + problems, distMgmt.getRepository(), "distributionManagement.repository.", "", true, true); validateRawRepository( problems, distMgmt.getSnapshotRepository(), "distributionManagement.snapshotRepository.", "", true, - false); + true); } } } diff --git a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultModelValidatorTest.java b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultModelValidatorTest.java index 1624fd3cb074..6e6f1d7b4970 100644 --- a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultModelValidatorTest.java +++ b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultModelValidatorTest.java @@ -896,18 +896,23 @@ void repositoryWithUnsupportedExpression() throws Exception { void repositoryWithUninterpolatedId() throws Exception { SimpleProblemCollector result = validateRaw("raw-model/repository-with-uninterpolated-id.xml"); // Uninterpolated expressions in repository IDs should cause validation errors - assertViolations(result, 0, 3, 0); + // distributionManagement repositories skip expression check since parent properties + // may not be available at file model validation stage + assertViolations(result, 0, 2, 0); - // Check that all three repository ID validation errors are present + // Check that repository ID validation errors are present for repositories and pluginRepositories assertTrue(result.getErrors().stream() .anyMatch(error -> error.contains("repositories.repository.[${repository.id}].id") && error.contains("contains an uninterpolated expression"))); assertTrue(result.getErrors().stream() .anyMatch(error -> error.contains("pluginRepositories.pluginRepository.[${plugin.repository.id}].id") && error.contains("contains an uninterpolated expression"))); - assertTrue(result.getErrors().stream() - .anyMatch(error -> error.contains("distributionManagement.repository.[${staging.repository.id}].id") - && error.contains("contains an uninterpolated expression"))); + } + + @Test + void distributionManagementWithChainedPropertyInId() throws Exception { + SimpleProblemCollector result = validateRaw("raw-model/dm-with-chained-property-in-id.xml"); + assertViolations(result, 0, 0, 0); } @Test diff --git a/impl/maven-impl/src/test/resources/poms/validation/raw-model/dm-with-chained-property-in-id.xml b/impl/maven-impl/src/test/resources/poms/validation/raw-model/dm-with-chained-property-in-id.xml new file mode 100644 index 000000000000..845da0a7c4bc --- /dev/null +++ b/impl/maven-impl/src/test/resources/poms/validation/raw-model/dm-with-chained-property-in-id.xml @@ -0,0 +1,46 @@ + + + + + 4.0.0 + + org.apache.maven.validation + project + 1.0.0-SNAPSHOT + + + ${distMgmtReleasesId} + ${distMgmtReleasesId} + + + + + ${distMgmtStagingId} + https://repository.apache.org/service/local/staging/deploy/maven2 + + + ${distMgmtSnapshotsId} + https://repository.apache.org/content/repositories/snapshots + + + +