Guides for SE student projects »

Caution: VS Code guides section is a work-in-progress, containing content contributed by students.

VS Code - Importing a Gradle project

  • Verify prerequisites:
    • Ensure you followed the section Preparing VS Code for Java projects above.
    • Verify the project has support for Gradle. If it does, you will see a build.gradle file in your project root.
  • Open the project in VS Code, as follows:
    • Open VS Code.
    • If you are in the welcome screen, Click Open. Otherwise, click File -> Open.
    • Select the project directory, and click Open.
  • Confirm the correct JDK is set to the one you are supposed to use for the project, as follows:
    • Open the Command Palette: / Ctrl+Shift+P | Cmd+Shift+P
    • Type Java: Configure Java Runtime and select it.
    • Check that the JDK version matches the one required for your project. If not, you can install the required JDK and configure it. (Java installation guides: Windows | Mac)
  • Confirm the correct JVM is used for Gradle, as follows:
    • Install the Gradle Extension: Search for Gradle in the Extensions view (Ctrl+Shift+X or Cmd+Shift+X), and install a Gradle extension if you haven’t already (e.g., Gradle for Java).
    • Open settings.json: You can find it by opening the Command Palette (Ctrl+Shift+P or Cmd+Shift+P), then typing Preferences: Open User Settings (JSON).
    • Add or modify the following settings to configure the JVM for Gradle. Here's an example (for Mac):
      settings.json
      {
        "java.configuration.runtimes": [
          {
            "name": "JavaSE-17",
            "path": "/Library/Java/JavaVirtualMachines/zulu-17.jdk/Contents/Home"
          }
        ],
        "java.import.gradle.java.home": "/Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home"
      }
      
    • If the Gradle icon doesn't appear after restarting VS Code, add "gradle.nestedProjects": true to your settings.json file.
  • Confirm you can access the Gradle tool window. After the importing of the project is complete (which could take a few minutes), you will see the Gradle Tab in the VSCode interface e.g., look for the elephant icon on the left and click it.

Contributors: Rui Shan (@ruishanteo)