diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultBuildPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultBuildPluginManager.java index 22822233e7..3ae2c58cc5 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultBuildPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultBuildPluginManager.java @@ -24,7 +24,6 @@ import org.apache.maven.model.Plugin; import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; @@ -39,9 +38,6 @@ public class DefaultBuildPluginManager implements BuildPluginManager { - @Requirement - private PlexusContainer container; - @Requirement private MavenPluginManager mavenPluginManager; @@ -86,8 +82,6 @@ public class DefaultBuildPluginManager throw new PluginExecutionException( mojoExecution, project, e ); } - ClassRealm oldLookupRealm = container.setLookupRealm( pluginRealm ); - ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader( pluginRealm ); @@ -159,7 +153,6 @@ public class DefaultBuildPluginManager mavenPluginManager.releaseMojo( mojo, mojoExecution ); Thread.currentThread().setContextClassLoader( oldClassLoader ); - container.setLookupRealm( oldLookupRealm ); legacySupport.setSession( oldSession ); } diff --git a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginManager.java index 5d467e8988..8d2dc92574 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginManager.java @@ -109,16 +109,16 @@ public class DefaultPluginManager throw new PluginManagerException( plugin, e.getMessage(), e ); } - ClassRealm oldRealm = container.getLookupRealm(); + ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); try { - container.setLookupRealm( pluginDescriptor.getClassRealm() ); + Thread.currentThread().setContextClassLoader( pluginDescriptor.getClassRealm() ); return container.lookup( role, roleHint ); } finally { - container.setLookupRealm( oldRealm ); + Thread.currentThread().setContextClassLoader( oldClassLoader ); } } @@ -141,16 +141,16 @@ public class DefaultPluginManager throw new PluginManagerException( plugin, e.getMessage(), e ); } - ClassRealm oldRealm = container.getLookupRealm(); + ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); try { - container.setLookupRealm( pluginDescriptor.getClassRealm() ); + Thread.currentThread().setContextClassLoader( pluginDescriptor.getClassRealm() ); return container.lookupMap( role ); } finally { - container.setLookupRealm( oldRealm ); + Thread.currentThread().setContextClassLoader( oldClassLoader ); } } 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 9949b8be82..b8cc4bb4f1 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 @@ -374,6 +374,9 @@ public class MavenCli container = new DefaultPlexusContainer( cc ); + // NOTE: To avoid inconsistencies, we'll use the TCCL exclusively for lookups + container.setLookupRealm( null ); + container.setLoggerManager( new MavenLoggerManager( logger ) ); customizeContainer( container );