Bazel
Bazel is an open-source build and test tool developed by Google. It is designed to manage large codebases with complex dependencies across multiple languages and platforms. Bazel automates the process of compiling code, linking dependencies, running tests, and deploying artifacts.
The JetBrains Bazel plugin may be useful to you but is not ready for many production use cases. Report any problems you encounter to our YouTrack issue tracker.
Install the Bazel plugin
This functionality relies on the Bazel plugin, which you need to install and enable. For more information, refer to Install a plugin from Marketplace.
Bazel support is implemented on top of a generic Build Server Protocol (BSP) that integrates a variety of build tools with the IDE. The protocol comes as a separate plugin that is installed automatically together with the JetBrains Bazel plugin.
Press Ctrl+Alt+S to open settings and then select
.Open the Marketplace tab, find the Bazel plugin, and click Install.
Restart the IDE to activate the plugin.
Open a project
Open a Bazel project
Click Open on the Welcome screen.
Alternatively, go to
in the main menu.In the dialog that opens, specify the path to the project sources.
You can watch the process of importing the project in the Build tool window:
Opening a Bazel project directory will create a default project view file projectview .bazelproject that loads the whole workspace.
Open a project subset
Since Bazel is commonly used for large-scale projects, you may want to open a project subset to ease the load on the IDE. The Bazel plugin generally supports the project view files feature as implemented by Google.
In the Project tool window (Alt+1 or in the main menu), right-click the predefined project view file and select Load Project View.
Alternatively, click Open on the Welcome screen or go to in the main menu and select the predefined project view file.
Resync project on file changes
When you change BUILD, WORKSPACE, MODULE.bazel or other build definition files, the IDE shows a popup with the button to update the loaded project structure. Click this icon to reload the project or press Ctrl+Shift+O.
You can also reload the project using the Bazel tool window.
In the main menu, go to
.In the Bazel tool window, click the Build and Resync Project button.
The Build and Resync Project option also runs a full build as part of the syncing process. This ensures that all generated source dependencies are available.
Build, run, and debug a project
Filter and search targets
In the Bazel tool window, you can filter runnable and testable targets.
In the main menu, go to
.Click the icon or search for a particular target by typing in the search field.
Run a target
In the main menu, go to
.Double-click a target in the target tree to trigger the default action: run a runnable target, or test a testable target.
Build a target
To build a specific target, go to
in the main menu.Right-click a target and select Build Target.
Build a project
In the main menu, go to
or press Ctrl+F9.
The Build Project action builds all targets.
Set up a run configuration
Whenever you run a Bazel target, the plugin automatically creates a temporary run configuration that you can edit as needed.
In the main menu, go to Run widget in the IDE window header.
or use theSelect a run configuration.
In the section on the right, change the settings as needed.
Run a test
Click the icon in the editor gutter next to the test you want to run.
Alternatively, right-click a target in the Bazel tool window and select Test Using Bazel.
Starlark support
The Bazel plugin provides code completion and navigation in Starlark files:
Debug Starlark code
Right-click the corresponding target in the Bazel tool window and select Starlark Debug.