From d29af9018b5c80177102aaab96bd37ed5fedf26c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Fri, 25 Feb 2022 11:46:07 +0100 Subject: [PATCH] [MNG-7402] BuildListCalculator never detaches the classloader This closes #683 --- .../lifecycle/internal/BuildListCalculator.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) 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 );