Bazel support for Java for Visual Studio Code
Installation
You can download the latest build from the Releases or package the extension by yourself:
- Install
vsce
CLI tool:npm install -g @vscode/vsce
- Clone the repository
git clone git@github.com:salesforce/bazel-vscode.git
- Install the dependencies:
cd bazel-vscode npm install
- Compile source code:
npm run compile
- Package the extension:
vsce package
- Open the Extensions tab in VS Code
- Select Install from VSIX... and choose file built in the fourth step
- Enable Bazel import and disable Maven import in VS Code settings (it can cause issues)
{ "java.import.bazel.enabled": true, "java.import.maven.enabled": false }
- Check source and test paths on the project. By default, source path is
/src/main/java
and test path is/src/test/java
. If source and/or test paths differ from the default, then add actual path in VS Code settingse.g.:{ "java.import.bazel.src.path": "<path-to-source>", "java.import.bazel.test.path": "<path-to-test>" }
{ "java.import.bazel.src.path": "/src/java", "java.import.bazel.test.path": "/src/tests" }
- Once installed, restart VS Code
Task Provider
You can use the example from the bazelTaskProvider.ts to create VSCode tasks.
The example provides tasks:
-
Run 'Build' and 'Test' to run bazel build an test for all targets.
-
Run 'Dependencies' query to creat all targets dependency graph.
-
Run 'Formatting' to formatt all BUILD and WORKSPACE files.
-
Run 'Unused deps' to check unused dependencies.
NOTE! Tasks 'Formatting' and 'Unused deps' require buildifier and unused deps installed respectively.
Remote Development
If you are using Visual Studio Code Remote Development for work, please note that 'Bazel' and other additional tools must be installed on the server.