Tibor17 edited a comment on pull request #285: URL: https://github.com/apache/maven-surefire/pull/285#issuecomment-619509634
@akomakom > However, to your point about excludedEnvironmentVariables always containing JAVA_HOME, perhaps this array should always contain anything configured in environmentVariables? It's not intuitive to me that specifying environmentVariables doesn't take effect unless I also exclude them. no, this is how env vars are implemented: `env vars in fork JVM` = `env vars in default JVM` + `environmentVariables` , where adding `env vars in default JVM` to the fork is performed by `maven-shared-utils`. [First we add](https://github.com/apache/maven-surefire/blob/master/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/DefaultForkConfiguration.java#L144) the `environmentVariables` to the `cli` then [we start executing the cli](https://github.com/apache/maven-surefire/blob/master/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java#L635) within which we [exclude the env vars of this default JVM](https://github.com/apache/maven-surefire/blob/master/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/OutputStreamFlushableCommandline.java#L66) by using the `excludedEnvironmentVariables` . So, in another words, the CLI will have `environmentVariables` as specified in the configuration and system env vars would not override them if they are listed in `excludedEnvironmentVariables`. Now I can see where we have a bug. This [line](https://github.com/apache/maven-surefire/blob/master/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/OutputStreamFlushableCommandline.java#L66) should have the condition `!envVars.containsKey( key )`. It is an overridden call from the `Commandline.class` in the library. We had to do it in order to implement the exclusion. We should add a backing object `Set<String>` of the env keys which have been added via `addEnvironment(String name, String value)`, see `OutputStreamFlushableCommandline`. This must be fixed, otherwise the system env vars will always override the `environmentVariables` from the configuration. ---------------------------------------------------------------- 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]
