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.
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 CtrlAlt0S to open settings and then select Plugins.
Open the Marketplace tab, find the Bazel plugin, and click Install.
Restart the IDE to activate the plugin.
Click Open on the Welcome screen.
Alternatively, go to File | Open 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:
![The Build tool window in the process of a Bazel project sync The Build tool window in the process of a Bazel project sync](https://resources.jetbrains.com/help/img/idea/2024.3/bazel-sync-build-tool.png)
Opening a Bazel project directory will create a default project view file projectview .bazelproject that loads the whole workspace.
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 (Alt01 or View | Tool Windows | Project 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 File | Open in the main menu and select the predefined project view file.
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 CtrlShift0O.
![The resync popup and the Bazel tool window The resync popup and the Bazel tool window](https://resources.jetbrains.com/help/img/idea/2024.3/bazel-sync-popup-and-window.png)
You can also reload the project using the Bazel tool window.
In the main menu, go to View | Tool Windows | Bazel.
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.
In the Bazel tool window, you can filter runnable and testable targets.
In the main menu, go to View | Tool Windows | Bazel.
Click the
icon or search for a particular target by typing in the search field.
In the main menu, go to View | Tool Windows | Bazel.
Double-click a target in the target tree to trigger the default action: run a runnable target, or test a testable target.
To build a specific target, go to View | Tool Windows | Bazel in the main menu.
Right-click a target and select Build Target.
In the main menu, go to Build | Build Project or press CtrlF9.
The Build Project action builds all targets.
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 | Edit Configurations or use the Run widget in the IDE window header.
Select a run configuration.
In the section on the right, change the settings as needed.
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.
![Code with a gutter icon and a context menu for a target with "Test using Bazel" selected. Code with a gutter icon and a context menu for a target with "Test using Bazel" selected.](https://resources.jetbrains.com/help/img/idea/2024.3/bazel-test-run.png)
The Bazel plugin provides code completion and navigation in Starlark files:
![Code completion suggestions in a Starlark file Code completion suggestions in a Starlark file](https://resources.jetbrains.com/help/img/idea/2024.3/bazel-starlark-completion.png)
Right-click the corresponding target in the Bazel tool window and select Starlark Debug.
Thanks for your feedback!