Skip to content

Commit

Permalink
Do not clone the session on maven >= 3.9.x, fixes takari#24
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed May 10, 2023
1 parent 0004c3a commit d84a987
Showing 1 changed file with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -64,6 +65,8 @@ class SmartBuilderImpl {
//
private final ReactorBuildStats stats;

private final boolean needsSessionClone;

class ProjectBuildTask implements ProjectRunnable {
private final MavenProject project;

Expand Down Expand Up @@ -103,6 +106,8 @@ public MavenProject getProject() {
this.executor = new ProjectExecutorService(degreeOfConcurrency, projectComparator);

this.stats = ReactorBuildStats.create(projects);

this.needsSessionClone = needsSessionClone(rootSession.getSystemProperties());
}

public ReactorBuildStats build() throws ExecutionException, InterruptedException {
Expand Down Expand Up @@ -200,7 +205,7 @@ private void submitAll(Set<MavenProject> 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) {
Expand All @@ -210,4 +215,24 @@ private void submitAll(Set<MavenProject> readyProjects) {
}
}

private static boolean needsSessionClone(Properties props) {
String version = props.getProperty("maven.version");
if (version != null) {
int i0 = version.indexOf(".");
int i1 = i0 > 0 ? version.indexOf(".", i0 + 1) : -1;
if (i1 > 0) {
try {
int maj = Integer.parseInt(version.substring(0, i0));
int min = Integer.parseInt(version.substring(i0 + 1, i1));
if (maj > 3 || (maj == 3 && min >= 9)) {
return false;
}
} catch (NumberFormatException e) {
// ignore
}
}
}
return true;
}

}

0 comments on commit d84a987

Please sign in to comment.