diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/BuildListCalculator.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/BuildListCalculator.java index 76454f810d..4fef69b4a9 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/BuildListCalculator.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/BuildListCalculator.java @@ -57,10 +57,18 @@ public class BuildListCalculator } for ( MavenProject project : projects ) { - BuilderCommon.attachToThread( project ); // Not totally sure if this is needed for anything - MavenSession copiedSession = session.clone(); - copiedSession.setCurrentProject( project ); - projectBuilds.add( new ProjectSegment( project, taskSegment, copiedSession ) ); + ClassLoader tccl = Thread.currentThread().getContextClassLoader(); + try + { + BuilderCommon.attachToThread( project ); // Not totally sure if this is needed for anything + MavenSession copiedSession = session.clone(); + copiedSession.setCurrentProject( project ); + projectBuilds.add( new ProjectSegment( project, taskSegment, copiedSession ) ); + } + finally + { + Thread.currentThread().setContextClassLoader( tccl ); + } } } return new ProjectBuildList( projectBuilds );