This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven.git
The following commit(s) were added to refs/heads/master by this push:
new 49fdd64cb7 Keep both repositories when a single mirror maps a POM
repository and a request repository to the same id (#14139)
49fdd64cb7 is described below
commit 49fdd64cb729c755dd02ede297a411b07eb02d9d
Author: Arturo Bernal <[email protected]>
AuthorDate: Fri Nov 27 10:08:57 2026 +0100
Keep both repositories when a single mirror maps a POM repository and a
request repository to the same id (#14139)
createArtifactRepositories() drops a recessive repository whose id already
appeared on the dominant side, assuming it is a duplicate. When a wildcard
mirror (mirrorOf=*) maps both a POM-declared repository and a request
repository (e.g. central, which Maven 4 supplies via the request
repositories
rather than the super POM) to the same mirror id, the two are not
duplicates:
each still carries only its own original release/snapshot policy, and
getEffectiveRepositories() needs both to merge them. Dropping either one
silently loses that side's policy, so a snapshots-only POM repository
mirrored
together with central leaves release artifacts unresolvable.
Keep a recessive repository that collides on id when both it and the
already-added
dominant repository are themselves mirror results, so both reach the policy
merge.
A plain id collision between two non-mirrored repositories is unaffected.
Fixes #14135
---
.../project/DefaultProjectBuildingHelper.java | 14 ++-
.../project/DefaultProjectBuildingHelperTest.java | 109 +++++++++++++++++++++
2 files changed, 122 insertions(+), 1 deletion(-)
diff --git
a/impl/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingHelper.java
b/impl/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingHelper.java
index 131dec8aed..c9fdddd3b8 100644
---
a/impl/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingHelper.java
+++
b/impl/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingHelper.java
@@ -122,17 +122,29 @@ public List<ArtifactRepository>
createArtifactRepositories(
List<ArtifactRepository> artifactRepositories = new ArrayList<>();
Collection<String> repoIds = new HashSet<>();
+ Collection<String> mirroredRepoIds = new HashSet<>();
if (dominantRepositories != null) {
for (ArtifactRepository repository : dominantRepositories) {
repoIds.add(repository.getId());
+ if (!repository.getMirroredRepositories().isEmpty()) {
+ mirroredRepoIds.add(repository.getId());
+ }
artifactRepositories.add(repository);
}
}
if (recessiveRepositories != null) {
for (ArtifactRepository repository : recessiveRepositories) {
- if (repoIds.add(repository.getId())) {
+ // A plain id collision (e.g. two repositories literally
declared with id "central")
+ // keeps the existing dominant-wins behavior. But when a
single mirror maps both
+ // sides to the same id (e.g. mirrorOf=*), both are mirror
results rather than a
+ // real collision, and dropping either one loses its
release/snapshot policy.
+ // Keep both so getEffectiveRepositories() below can merge
their policies, the same
+ // way it already does when both mirrored copies come from the
dominant side.
+ if (repoIds.add(repository.getId())
+ || (mirroredRepoIds.contains(repository.getId())
+ &&
!repository.getMirroredRepositories().isEmpty())) {
artifactRepositories.add(repository);
}
}
diff --git
a/impl/maven-core/src/test/java/org/apache/maven/project/DefaultProjectBuildingHelperTest.java
b/impl/maven-core/src/test/java/org/apache/maven/project/DefaultProjectBuildingHelperTest.java
new file mode 100644
index 0000000000..e5f3fd6307
--- /dev/null
+++
b/impl/maven-core/src/test/java/org/apache/maven/project/DefaultProjectBuildingHelperTest.java
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.project;
+
+import javax.inject.Inject;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.maven.MavenTestHelper;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
+import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
+import org.apache.maven.bridge.MavenRepositorySystem;
+import org.apache.maven.model.Repository;
+import org.apache.maven.model.RepositoryPolicy;
+import org.codehaus.plexus.PlexusContainer;
+import org.codehaus.plexus.testing.PlexusTest;
+import org.eclipse.aether.DefaultRepositorySystemSession;
+import org.eclipse.aether.util.repository.DefaultMirrorSelector;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@PlexusTest
+class DefaultProjectBuildingHelperTest {
+
+ @Inject
+ private DefaultProjectBuildingHelper helper;
+
+ @Inject
+ private MavenRepositorySystem repositorySystem;
+
+ @Inject
+ private PlexusContainer container;
+
+ /**
+ * A POM-declared repository and a request repository (e.g. the project's
remote repositories, where Maven 4
+ * puts {@code central} instead of the super POM) can end up mapped to the
same mirror id by a single wildcard
+ * mirror. Each side only carries its own original release/snapshot
policy, so both copies must reach
+ * {@link MavenRepositorySystem#getEffectiveRepositories} to be merged;
dropping either one as a duplicate id
+ * silently loses that side's policy (GitHub #14135).
+ */
+ @Test
+ void mergesPoliciesWhenAPomRepositoryAndARequestRepositoryShareAMirrorId()
throws Exception {
+ DefaultMirrorSelector mirrorSelector = new DefaultMirrorSelector()
+ .add("all", "https://repo.example.com/mirror", "default",
false, false, "*", null);
+
+ DefaultRepositorySystemSession repoSession =
MavenTestHelper.createSession(repositorySystem, container);
+ repoSession.setMirrorSelector(mirrorSelector);
+
+ // The project's remote repositories: central, releases enabled /
snapshots disabled, already mirrored
+ // the way it would be by the time DefaultProjectBuildingHelper sees
it in the real pipeline.
+ ArtifactRepository central =
MavenRepositorySystem.createArtifactRepository(
+ "central",
+ "https://repo.maven.apache.org/maven2",
+ new DefaultRepositoryLayout(),
+ new ArtifactRepositoryPolicy(false, null, null),
+ new ArtifactRepositoryPolicy(true, null, null));
+ List<ArtifactRepository> externalRepositories = new ArrayList<>();
+ externalRepositories.add(central);
+ repositorySystem.injectMirror(repoSession, externalRepositories);
+
+ // The POM declares a snapshots-only repository, matched by the same
wildcard mirror.
+ Repository snaps = new Repository();
+ snaps.setId("snaps");
+ snaps.setUrl("https://repository.apache.org/snapshots");
+ RepositoryPolicy releasesDisabled = new RepositoryPolicy();
+ releasesDisabled.setEnabled(false);
+ snaps.setReleases(releasesDisabled);
+ RepositoryPolicy snapshotsEnabled = new RepositoryPolicy();
+ snapshotsEnabled.setEnabled(true);
+ snaps.setSnapshots(snapshotsEnabled);
+
+ DefaultProjectBuildingRequest request = new
DefaultProjectBuildingRequest();
+ request.setRepositorySession(repoSession);
+
+ List<ArtifactRepository> effectiveRepositories =
+
helper.createArtifactRepositories(Collections.singletonList(snaps),
externalRepositories, request);
+
+ assertEquals(1, effectiveRepositories.size(), "both sides map to the
same mirror id and must merge into one");
+ ArtifactRepository effective = effectiveRepositories.get(0);
+ assertEquals("all", effective.getId());
+ assertTrue(
+ effective.getReleases().isEnabled(),
+ "the mirrored central side's release policy must survive the
merge");
+ assertTrue(
+ effective.getSnapshots().isEnabled(),
+ "the mirrored POM repository's snapshot policy must survive
the merge");
+ }
+}