Caution: This page is a work-in-progress, containing content contributed by students.
This guide is for those who prefer to use Visual Studio Code (VS Code) for their Java projects.
Extensions
→ Search Extension Pack for Java
→ Install.build.gradle
file in your project root.Open
. Otherwise, click File
-> Open
.Open
.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).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)
.{
"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"
}
"gradle.nestedProjects": true
to your settings.json
file.Given below are the steps to set up a Checkstyle plugin in VS Code so that VS Code can alert you about code style problems as you write code.
checkstyle.xml
and suppressions.xml
) should be in the ./config/checkstyle
directory, as mentioned here.Extensions
-> Search Checkstyle for Java
-> Install (the first entry).File -> Open Folder...
../.vscode/settings.json
file exists. If not, create a folder .vscode
in the project root directory and add a file settings.json
within the .vscode
folder. This file contains configuration settings for projects in VS Code.settings.json
file. These settings ensure that the Checkstyle extension uses the correct configuration files in the ./config/checkstyle
directory: {
"java.checkstyle.configuration": "${workspaceFolder}/config/checkstyle/checkstyle.xml",
"java.checkstyle.properties": {
"config_loc": "${workspaceFolder}/config/checkstyle"
}
}
.vscode
to your .gitignore
if you haven't done so by adding these few lines to the end of .gitignore
:# VS Code
/.vscode/
Problems
tab in VS Code. For example, after changing the code to add a wildcard import, you can see that the wildcard import on line 11 has been detected by the Checkstyle extension: