+ * Note: this component should kick-in last regarding relocations.
+ *
+ * @since 4.0.0
+ */
+@Singleton
+@Named
+@Priority(5)
+@SuppressWarnings("checkstyle:MagicNumber")
+public final class DistributionManagementArtifactRelocationSource implements MavenArtifactRelocationSource {
+ private static final Logger LOGGER = LoggerFactory.getLogger(DistributionManagementArtifactRelocationSource.class);
+
+ @Override
+ public Artifact relocatedTarget(RepositorySystemSession session, ArtifactDescriptorRequest request, Model model) {
+ DistributionManagement distMgmt = model.getDistributionManagement();
+ if (distMgmt != null) {
+ Relocation relocation = distMgmt.getRelocation();
+ if (relocation != null) {
+ Artifact result = new RelocatedArtifact(
+ request.getArtifact(),
+ relocation.getGroupId(),
+ relocation.getArtifactId(),
+ null,
+ null,
+ relocation.getVersion(),
+ relocation.getMessage());
+ LOGGER.debug(
+ "The artifact {} has been relocated to {}: {}",
+ request.getArtifact(),
+ result,
+ relocation.getMessage());
+ return result;
+ }
+ }
+ return null;
+ }
+}
diff --git a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/relocation/UserPropertiesArtifactRelocationSource.java b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/relocation/UserPropertiesArtifactRelocationSource.java
new file mode 100644
index 000000000000..fd3710b9e93b
--- /dev/null
+++ b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/relocation/UserPropertiesArtifactRelocationSource.java
@@ -0,0 +1,201 @@
+/*
+ * 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.repository.internal.relocation;
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Objects;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import org.apache.maven.model.Model;
+import org.apache.maven.repository.internal.MavenArtifactRelocationSource;
+import org.apache.maven.repository.internal.RelocatedArtifact;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.artifact.DefaultArtifact;
+import org.eclipse.aether.resolution.ArtifactDescriptorRequest;
+import org.eclipse.sisu.Priority;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Relocation source from user properties.
+ *
+ * @since 4.0.0
+ */
+@Singleton
+@Named
+@Priority(50)
+@SuppressWarnings("checkstyle:MagicNumber")
+public final class UserPropertiesArtifactRelocationSource implements MavenArtifactRelocationSource {
+ private static final Logger LOGGER = LoggerFactory.getLogger(UserPropertiesArtifactRelocationSource.class);
+
+ private static final String CONFIG_PROP_RELOCATIONS_ENTRIES = "maven.relocations.entries";
+
+ @Override
+ public Artifact relocatedTarget(RepositorySystemSession session, ArtifactDescriptorRequest request, Model model) {
+ Relocations relocations = (Relocations) session.getData()
+ .computeIfAbsent(getClass().getName() + ".relocations", () -> parseRelocations(session));
+ if (relocations != null) {
+ Relocation relocation = relocations.getRelocation(request.getArtifact());
+ if (relocation != null && (isProjectContext(request.getRequestContext()) || relocation.global)) {
+ Artifact result = new RelocatedArtifact(
+ request.getArtifact(),
+ isAny(relocation.target.getGroupId()) ? null : relocation.target.getGroupId(),
+ isAny(relocation.target.getArtifactId()) ? null : relocation.target.getArtifactId(),
+ isAny(relocation.target.getClassifier()) ? null : relocation.target.getClassifier(),
+ isAny(relocation.target.getExtension()) ? null : relocation.target.getExtension(),
+ isAny(relocation.target.getVersion()) ? null : relocation.target.getVersion(),
+ relocation.global ? "User global relocation" : "User project relocation");
+ LOGGER.debug(
+ "The artifact {} has been relocated to {}: {}",
+ request.getArtifact(),
+ result,
+ relocation.global ? "User global relocation" : "User project relocation");
+ return result;
+ }
+ }
+ return null;
+ }
+
+ private boolean isProjectContext(String context) {
+ return context != null && context.startsWith("project");
+ }
+
+ private static boolean isAny(String str) {
+ return "*".equals(str);
+ }
+
+ private static boolean matches(String pattern, String str) {
+ if (isAny(pattern)) {
+ return true;
+ } else if (pattern.endsWith("*")) {
+ return str.startsWith(pattern.substring(0, pattern.length() - 1));
+ } else {
+ return Objects.equals(pattern, str);
+ }
+ }
+
+ private static Predicate