From 906468ba2dd9b7e8add50d0768f3ac4ac88bc3d5 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Tue, 12 Apr 2022 19:55:22 +0200 Subject: [PATCH 1/2] [MNG-7455] Minimal fix for the concurrency issue --- .../lifecycle/internal/LifecycleModuleBuilder.java | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleModuleBuilder.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleModuleBuilder.java index 1cbaf5334606..50225f119c9a 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleModuleBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleModuleBuilder.java @@ -88,14 +88,6 @@ public void buildProject( MavenSession session, MavenSession rootSession, Reacto long buildStartTime = System.currentTimeMillis(); - // session may be different from rootSession seeded in DefaultMaven - // explicitly seed the right session here to make sure it is used by Guice - final boolean scoped = session != rootSession; - if ( scoped ) - { - sessionScope.enter(); - sessionScope.seed( MavenSession.class, session ); - } try { @@ -149,11 +141,6 @@ public void buildProject( MavenSession session, MavenSession rootSession, Reacto } finally { - if ( scoped ) - { - sessionScope.exit(); - } - session.setCurrentProject( null ); Thread.currentThread().setContextClassLoader( reactorContext.getOriginalContextClassLoader() ); From d24adb7f5d4a86bbcf7d2e7ef37dc933534a37da Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Tue, 12 Apr 2022 20:07:35 +0200 Subject: [PATCH 2/2] Add some javadoc --- maven-core/src/main/java/org/apache/maven/SessionScoped.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/maven-core/src/main/java/org/apache/maven/SessionScoped.java b/maven-core/src/main/java/org/apache/maven/SessionScoped.java index 7738938c06f4..8f6ec4d8c1cb 100644 --- a/maven-core/src/main/java/org/apache/maven/SessionScoped.java +++ b/maven-core/src/main/java/org/apache/maven/SessionScoped.java @@ -31,6 +31,11 @@ * Indicates that annotated component should be instantiated before session execution starts * and discarded after session execution completes. * + * Note that components will be cached in the session scope and be injected with the root session. + * Derived sessions will reuse the same components than their root sessions, thus components + * should not rely on {@link org.apache.maven.execution.MavenSession#getCurrentProject()} which + * will always return the root project. + * * @author Jason van Zyl * @since 3.2.0 */