From 9ced72c8578825cdc8ea5c49a59f921a7157b772 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Wed, 10 May 2023 20:42:38 +0200 Subject: [PATCH] Do not clone the session on maven >= 3.9.x, fixes #24 --- .../maven/builder/smart/SmartBuilderImpl.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/takari/maven/builder/smart/SmartBuilderImpl.java b/src/main/java/io/takari/maven/builder/smart/SmartBuilderImpl.java index 3a5e0dd..e7e7e91 100644 --- a/src/main/java/io/takari/maven/builder/smart/SmartBuilderImpl.java +++ b/src/main/java/io/takari/maven/builder/smart/SmartBuilderImpl.java @@ -22,6 +22,7 @@ * the License. */ +import org.apache.maven.artifact.versioning.DefaultArtifactVersion; import org.apache.maven.execution.BuildFailure; import org.apache.maven.execution.BuildSuccess; import org.apache.maven.execution.BuildSummary; @@ -200,7 +201,7 @@ private void submitAll(Set readyProjects) { logger.debug("STARTED build of project {}:{}", project.getGroupId(), project.getArtifactId()); try { - MavenSession copiedSession = rootSession.clone(); + MavenSession copiedSession = needsSessionClone() ? rootSession.clone() : rootSession; lifecycleModuleBuilder.buildProject(copiedSession, rootSession, reactorContext, project, taskSegment); } catch (RuntimeException ex) { @@ -210,4 +211,15 @@ private void submitAll(Set readyProjects) { } } + private static boolean needsSessionClone() { + String version = System.getProperty("maven.version"); + if (version != null) { + DefaultArtifactVersion v = new DefaultArtifactVersion(version); + if (v.getMajorVersion() > 3 || (v.getMajorVersion() == 3 && v.getMinorVersion() >= 9)) { + return false; + } + } + return true; + } + }