diff --git a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/LookupInvoker.java b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/LookupInvoker.java index 00bd9c658e..971e0cedbd 100644 --- a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/LookupInvoker.java +++ b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/LookupInvoker.java @@ -501,8 +501,12 @@ public abstract class LookupInvoker implements Invoker * If there are Maven3 passwords presents in settings, this results in doubled warnings emitted. So Plexus DI * creation call keeps "emitSettingsWarnings" false. If there are fatal issues, it will anyway "die" at that * spot before warnings would be emitted. + *

+ * The method returns a "cleaner" runnable, as during extension loading the context needs to be "cleaned", restored + * to previous state (as it was before extension loading). */ - protected void settings(C context, boolean emitSettingsWarnings, SettingsBuilder settingsBuilder) throws Exception { + protected Runnable settings(C context, boolean emitSettingsWarnings, SettingsBuilder settingsBuilder) + throws Exception { Options mavenOptions = context.invokerRequest.options(); Path userSettingsFile = null; @@ -612,6 +616,14 @@ public abstract class LookupInvoker implements Invoker } context.logger.info(""); } + return () -> { + context.installationSettingsPath = null; + context.projectSettingsPath = null; + context.userSettingsPath = null; + context.effectiveSettings = null; + context.interactive = true; + context.localRepositoryPath = null; + }; } protected void customizeSettingsRequest(C context, SettingsBuilderRequest settingsBuilderRequest) diff --git a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/PlexusContainerCapsuleFactory.java b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/PlexusContainerCapsuleFactory.java index 2f38469843..56d6cc099f 100644 --- a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/PlexusContainerCapsuleFactory.java +++ b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/PlexusContainerCapsuleFactory.java @@ -273,13 +273,14 @@ public class PlexusContainerCapsuleFactory implements C }); ClassLoader oldCL = Thread.currentThread().getContextClassLoader(); + Runnable settingsCleaner = null; try { container.setLookupRealm(null); container.setLoggerManager(createLoggerManager()); container.getLoggerManager().setThresholds(toPlexusLoggingLevel(context.loggerLevel)); Thread.currentThread().setContextClassLoader(container.getContainerRealm()); - invoker.settings(context, false, container.lookup(SettingsBuilder.class)); + settingsCleaner = invoker.settings(context, false, container.lookup(SettingsBuilder.class)); MavenExecutionRequest mer = new DefaultMavenExecutionRequest(); invoker.populateRequest(context, new DefaultLookup(container), mer); @@ -288,6 +289,9 @@ public class PlexusContainerCapsuleFactory implements C .lookup(BootstrapCoreExtensionManager.class) .loadCoreExtensions(mer, providedArtifacts, extensions)); } finally { + if (settingsCleaner != null) { + settingsCleaner.run(); + } try { container.dispose(); } finally {