From f96c6bcbc1e20ddaa95e0bbc29d36a975953a95c Mon Sep 17 00:00:00 2001 From: Matthias Kampmeyer Date: Mon, 17 Apr 2023 11:32:35 +0200 Subject: [PATCH] [MRELEASE-851] javaHome parameter is ignored and inherited unexpectedly This closes #182 --- .../apache/maven/shared/release/exec/ForkedMavenExecutor.java | 4 ++++ .../maven/shared/release/exec/InvokerMavenExecutor.java | 1 + .../org/apache/maven/plugins/release/AbstractReleaseMojo.java | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/ForkedMavenExecutor.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/ForkedMavenExecutor.java index 2b8d9f62..7a807aaf 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/ForkedMavenExecutor.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/ForkedMavenExecutor.java @@ -106,6 +106,10 @@ public void executeGoals( cl.addEnvironment("MAVEN_TERMINATE_CMD", "on"); + if (releaseEnvironment.getJavaHome() != null) { + cl.addEnvironment("JAVA_HOME", releaseEnvironment.getJavaHome().getAbsolutePath()); + } + if (settingsFile != null) { cl.createArg().setValue("-s"); cl.createArg().setFile(settingsFile); diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/InvokerMavenExecutor.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/InvokerMavenExecutor.java index 51d83df3..7a60e629 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/InvokerMavenExecutor.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/InvokerMavenExecutor.java @@ -76,6 +76,7 @@ public void executeGoals( // fix for MRELEASE-1105 // .addShellEnvironment( "MAVEN_DEBUG_OPTS", "" ) .setBatchMode(true) + .setJavaHome(releaseEnvironment.getJavaHome()) .setOutputHandler(getLogger()::info) .setErrorHandler(getLogger()::error); diff --git a/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/AbstractReleaseMojo.java b/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/AbstractReleaseMojo.java index 825f441e..99c48351 100644 --- a/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/AbstractReleaseMojo.java +++ b/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/AbstractReleaseMojo.java @@ -91,7 +91,7 @@ public abstract class AbstractReleaseMojo extends AbstractMojo { private File mavenHome; /** - * The {@code JAVA_HOME} parameter to use for forked Maven invocations. + * The Java home parameter to use for forked Maven invocations. * * @since 2.0-beta-8 */