From 9b407d57dc7cc596ddb4cc2b48613f3531d3aa55 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Fri, 18 Oct 2024 09:44:40 +0200 Subject: [PATCH] [MNG-8327] Failure when building the consumer POM --- .../org/apache/maven/project/DefaultProjectBuilder.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java index 954d3faf6d..9de384e9e6 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java @@ -323,7 +323,12 @@ public class DefaultProjectBuilder implements ProjectBuilder { RepositoryUtils.overlay(request.getLocalRepository(), request.getRepositorySession(), repoSystem); InternalSession iSession = InternalSession.from(session); this.modelBuilderSession = modelBuilder.newSession(); - iSession.getData().set(SessionData.key(ModelBuilder.ModelBuilderSession.class), modelBuilderSession); + // Save the ModelBuilderSession for later retrieval by the DefaultConsumerPomBuilder. + // Use replace(key, null, value) to make sure the *main* session, i.e. the one used + // to load the projects, is stored. This is to avoid the session being overwritten + // if a plugin uses the ProjectBuilder. + iSession.getData() + .replace(SessionData.key(ModelBuilder.ModelBuilderSession.class), null, modelBuilderSession); } @Override