The Windows 10 system environment variables JAVA_HOME
and PATH
are pointing to JDK 18 which is needed to launch VS Code and needed by other applications on the laptop.
I configured Maven Project in VS Code with JRE/Java Runtime pointing to JDK 1.8 which is required for the project to compile and build correctly. All is working fine.
When I run Maven Goals such as mvn clean install
either using ctrl-shift-p
and execute maven command
, or by running a build from Maven View/Lifecycle entry. A terminal is launched and it will inherit the system environment variables. In order to avoid this problem, I always cancel the launched maven command in the PowerShell terminal by pressing ctrl-c
and change the environment variables using:
$ENV:Path="C:\apps\jdk1.8.0_351\bin;"+$ENV:Path
$env:JAVA_HOME="C:\apps\jdk1.8.0_351"
... then run the maven goal again.
I also added a favorite in Maven View/Favorites to launch the maven goal as follows:
"maven.terminal.favorites": [
{
"command": "clean install \"-Dmaven.test.skip=true\"",
"debug": false
}
]
When I run the above goal, it will always inherit the system values, and I have to change them again as mentioned earlier.
In addition, if I try to run a goal from Mave View/Plugins/Install by right-clicking and clicking debug, it will always launch a new PowerShell terminal which will inherit the system environment variables, and I didn't find a way to change this.
I am thinking that VS Code should set the environment correctly when running Maven Goals based on the JRE configured in VS Code Workspace setting.json file, but this is not happening.
When I configured Debug Request in launch.json
, it is respecting the JDK defined for the project, so why it is not respecting this setting when running maven goals?
I think I can solve this problem by configuring a task that will run the maven goal in PowerShell script by I think this is a bit complex for such a simple requirement.
How I can solve this problem without configuring a new task? I am thinking there is a config somewhere to set JRE for Maven Goals for a given project.