diff --git a/maven-core/src/main/java/org/apache/maven/project/RepositoryModelResolver.java b/maven-core/src/main/java/org/apache/maven/project/RepositoryModelResolver.java index efbfd3793e..2d686a02f5 100644 --- a/maven-core/src/main/java/org/apache/maven/project/RepositoryModelResolver.java +++ b/maven-core/src/main/java/org/apache/maven/project/RepositoryModelResolver.java @@ -21,7 +21,9 @@ package org.apache.maven.project; import java.util.ArrayList; import java.util.Arrays; +import java.util.Iterator; import java.util.List; +import java.util.Map; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.repository.ArtifactRepository; @@ -88,7 +90,19 @@ class RepositoryModelResolver try { ArtifactRepository repo = repositorySystem.buildArtifactRepository( repository ); - remoteRepositories.addAll( 0, repositorySystem.getMirrors( Arrays.asList( repo ) ) ); + + ArtifactRepository mirror = repositorySystem.getMirrors( Arrays.asList( repo ) ).get( 0 ); + + for ( Iterator it = remoteRepositories.iterator(); it.hasNext(); ) + { + ArtifactRepository remoteRepository = it.next(); + if ( mirror.getId().equals( remoteRepository.getId() ) ) + { + it.remove(); + } + } + + remoteRepositories.add( 0, mirror ); } catch ( org.apache.maven.artifact.InvalidRepositoryException e ) { diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/resolution/ModelResolver.java b/maven-model-builder/src/main/java/org/apache/maven/model/resolution/ModelResolver.java index 98e715878c..cce54632d8 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/resolution/ModelResolver.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/resolution/ModelResolver.java @@ -33,9 +33,25 @@ import org.apache.maven.model.Repository; public interface ModelResolver { + /** + * Tries to resolve the POM for the specified coordinates. + * + * @param groupId The group identifier of the POM, must not be {@code null}. + * @param artifactId The artifact identifier of the POM, must not be {@code null}. + * @param version The version of the POM, must not be {@code null}. + * @return The source of the requested POM, never {@code null}. + * @throws UnresolvableModelException If the POM could not be resolved from any configured repository. + */ ModelSource resolveModel( String groupId, String artifactId, String version ) throws UnresolvableModelException; + /** + * Adds a repository to use for subsequent resolution requests. The order in which repositories are added matters. + * When multiple repositories with the same identifier are added, only the last repository being added will be used. + * + * @param repository The repository to add to the internal search chain, must not be {@code null}. + * @throws InvalidRepositoryException If the repository could not be added (e.g. due to invalid URL or layout). + */ void addRepository( Repository repository ) throws InvalidRepositoryException;