Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not clone the session on maven >= 3.9.x, fixes #24 #25

Merged
merged 1 commit into from
May 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}

}