Skip to content
Advertisement

How to configure VSCode on Linux to make it apply different JAVA_HOME for Gradle in different projects?

Right now I have a Spring project (needs Java 17) and a minecraft-forge-1.12 project (needs Java 8) on the same system.

I want vscode to automatically change JAVA_HOME between /usr/lib/jvm/java-17-openjdk-amd64 and /usr/lib/jvm/java-8-openjdk-amd64 for gradlew command when I switch between these two project.

I tried using .vscode/settings.json to do that, but java.import.gradle.java.home cannot change in settings.json, so I can’t change this for Gradle.

Is there a way doing that?

Advertisement

Answer

Set up the Java runtime separately for your project workspace.

  • Ctrl+Shift+P pen the control panel and select Preferences:Open Workspace Setting(JSON)

    enter image description here

  • Add the following configuration to the settings.json file

// Just an example, please modify it to your own path

    "java.configuration.runtimes": [
        {
            "name": "JavaSE-1.8",
            "path": "C:\Program Files\Eclipse Adoptium\jdk-8.0.332.9-hotspot",
            "default" : true,
        },
        {
            "name": "JavaSE-17",
            "path": "C:\Users\Admin\AppData\Local\Programs\Eclipse Adoptium\jdk-17.0.3.7-hotspot",
        }
    ],
  • Change "default" : true for different workspace.
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement