From 7f86d1d996bab2c2986eca06e7e9c94b543fc48a Mon Sep 17 00:00:00 2001 From: juulhobert Date: Wed, 18 Oct 2023 20:06:57 +0200 Subject: [PATCH] [MNG-7772] Allow to register maven core extension in .m2 directory instead of MAVEN_HOME (#1280) --- apache-maven/src/assembly/maven/bin/m2.conf | 1 + .../java/org/apache/maven/cli/MavenCli.java | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/apache-maven/src/assembly/maven/bin/m2.conf b/apache-maven/src/assembly/maven/bin/m2.conf index c050dc07bf..15e0f5df2e 100644 --- a/apache-maven/src/assembly/maven/bin/m2.conf +++ b/apache-maven/src/assembly/maven/bin/m2.conf @@ -6,6 +6,7 @@ set maven.conf default ${maven.home}/conf load ${maven.conf}/logging optionally ${maven.home}/lib/ext/redisson/*.jar optionally ${maven.home}/lib/ext/hazelcast/*.jar +optionally ${user.home}/.m2/ext/*.jar optionally ${maven.home}/lib/ext/*.jar load ${maven.home}/lib/maven-*.jar load ${maven.home}/lib/*.jar diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java index 7c620ce5e9..f9d532f200 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java @@ -145,7 +145,9 @@ public class MavenCli { private static final String EXT_CLASS_PATH = "maven.ext.class.path"; - private static final String EXTENSIONS_FILENAME = ".mvn/extensions.xml"; + private static final String EXTENSIONS_FILENAME = "extensions.xml"; + + private static final String MVN_EXTENSIONS_FILENAME = ".mvn/" + EXTENSIONS_FILENAME; private static final String MVN_MAVEN_CONFIG = ".mvn/maven.config"; @@ -747,12 +749,17 @@ public class MavenCli { return Collections.emptyList(); } - File extensionsFile = new File(cliRequest.multiModuleProjectDirectory, EXTENSIONS_FILENAME); - if (!extensionsFile.isFile()) { - return Collections.emptyList(); + File extensionsFile = new File(cliRequest.multiModuleProjectDirectory, MVN_EXTENSIONS_FILENAME); + File userHomeExtensionsFile = new File(USER_MAVEN_CONFIGURATION_HOME, EXTENSIONS_FILENAME); + + List extensions = new ArrayList<>(); + if (extensionsFile.isFile()) { + extensions.addAll(readCoreExtensionsDescriptor(extensionsFile)); + } + if (userHomeExtensionsFile.isFile()) { + extensions.addAll(readCoreExtensionsDescriptor(userHomeExtensionsFile)); } - List extensions = readCoreExtensionsDescriptor(extensionsFile); if (extensions.isEmpty()) { return Collections.emptyList(); }