akomakom edited a comment on pull request #285:
URL: https://github.com/apache/maven-surefire/pull/285#issuecomment-619460223
So the implementation might look like this:
```diff
diff --git
a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
index 8a0cd0aac..f29f48b04 100644
---
a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
+++
b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
@@ -59,6 +59,7 @@
import org.apache.maven.project.MavenProject;
import
org.apache.maven.shared.artifact.filter.PatternIncludesArtifactFilter;
import
org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolver;
+import org.apache.maven.surefire.shared.lang3.ArrayUtils;
import org.apache.maven.surefire.shared.utils.io.FileUtils;
import org.apache.maven.surefire.booter.ClassLoaderConfiguration;
import org.apache.maven.surefire.booter.Classpath;
@@ -89,6 +90,7 @@
import org.apache.maven.toolchain.DefaultToolchain;
import org.apache.maven.toolchain.Toolchain;
import org.apache.maven.toolchain.ToolchainManager;
+import org.apache.maven.toolchain.java.DefaultJavaToolChain;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.languages.java.jpms.LocationManager;
import org.codehaus.plexus.languages.java.jpms.ResolvePathsRequest;
@@ -97,6 +99,7 @@
import javax.annotation.Nonnull;
import java.io.File;
import java.io.IOException;
+import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.nio.file.Files;
@@ -2555,6 +2558,24 @@ private JdkAttributes getEffectiveJvm() throws
MojoFailureException
||
defaultToolchain.matchesRequirements( JAVA_9_MATCHER_OLD_NOTATION );
}
+ if ( toolchain instanceof DefaultJavaToolChain )
+ {
+ DefaultJavaToolChain defaultJavaToolChain =
(DefaultJavaToolChain) toolchain;
+ environmentVariables.put( "JAVA_HOME",
defaultJavaToolChain.getJavaHome() );
+ try
+ {
+ Field excludedEnvironmentVariables =
getClass().getDeclaredField( "excludedEnvironmentVariables" );
+ excludedEnvironmentVariables.setAccessible( true );
+ excludedEnvironmentVariables.set( this,
+ ArrayUtils.add(
getExcludedEnvironmentVariables(), "JAVA_HOME" ));
+ } catch ( NoSuchFieldException | IllegalAccessException
x ) {
+ if ( logger.isDebugEnabled() )
+ {
+ logger.debug( "No
setExcludedEnvironmentVariables field on class " + getClass(), x );
+ }
+ }
+ }
+
if ( !javaVersion9 )
```
:arrow_up: This works
Unfortunately, without putting JAVA_HOME on the exclude list, this won't
work and exclude list is implemented differently in each plugin (I assume that
this is for the sake of having different user properties), hence the ugly
reflection.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]