Home > OS >  Intellij IDEA terminal shows wrong jVM version with ./gradlew -version or mvn -version
Intellij IDEA terminal shows wrong jVM version with ./gradlew -version or mvn -version

Time:01-31

Normally I have to work with multiple java versions for multiple projects. Therefore what I normally do is change the java path for the particular version from the environment variables.

While I am using the IntelliJ idea, sometimes even though I changed the java path in environment variables IntelliJ idea terminal is showing the wrong jvm version when ./gradlew -version or mvn -version commands are executed. But real PowerShell, command prompt or git bash is showing the correct jvm version when executing the above commands.

I double checked in the IntelliJ idea

  1. Flie -> Project Structure
  2. File -> Settings Buidl, Execution, Deployment -> Gradle -> all the options and Tools -> Terminal -> in Environment Variables, correct java path is set
  3. Project Configurations

All above are set as they should be with the correct java version and path.

CodePudding user response:

If you use the terminal for running command lines in the IDE, you can specify the JAVA_HOME variable from Settings | Tools | Terminal | Environment variables configuration.

If you run Maven goals/Gradle tasks from the build tool window, you can specify which JRE to use from Settings | Build, Execution, Deployment | Build Tools | Maven | Runner for Maven, and Settings | Build, Execution, Deployment | Build Tools | Gradle | Gradle JVM for Gradle.

CodePudding user response:

Found another solution after a few days, this question was raised.

If you are working with IntelliJ IDEA. There is a solution, If you are working in multiple projects and the java versions of those projects are different, you can easily switch the java version of the intellij idea terminal without changing the windows system variable paths.

I am using IntelliJ IDEA 2022.3.1 (Community Edition)

  1. Go to File -> Settings
  2. In the pop-up window's left side panel, Got to Tools -> Terminal

enter image description here

  1. Click on the right-side icon of the Environment variables field.

enter image description here

  1. Set Java_Home as <Your Java folder path - without bin>

Note: In the attached screenshots rather than java it is mentioned as corretto for the Environment variables and the JAVA_HOME path. Folks who have no idea about corretto and java, please consider they are same.

  • Related