IntelliJ IDEA 2024.3 Help

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.

  1. Press Ctrl+Alt+S to open settings and then select Plugins.

  2. Open the Marketplace tab, find the Bazel plugin, and click Install.

  3. Restart the IDE to activate the plugin.

Open a project

Open a Bazel project

  1. Click Open on the Welcome screen.

    Alternatively, go to File | Open in the main menu.

  2. 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

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 View | Tool Windows | Project in the main menu), right-click the predefined project view file and select Load Project View.

    The Project tool window with a context menu for a .bazelproject file
  • Alternatively, click Open on the Welcome screen or go to File | Open 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.

The resync popup and the Bazel tool window

You can also reload the project using the Bazel tool window.

  1. In the main menu, go to View | Tool Windows | Bazel.

  2. 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.

  1. In the main menu, go to View | Tool Windows | Bazel.

  2. Click the icon or search for a particular target by typing in the search field.

    The resync popup and the Bazel tool window

Run a target

  1. In the main menu, go to View | Tool Windows | Bazel.

  2. 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

  1. To build a specific target, go to View | Tool Windows | Bazel in the main menu.

  2. Right-click a target and select Build Target.

Build a project

  • In the main menu, go to Build | Build Project 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.

  1. In the main menu, go to Run | Edit Configurations or use the Run widget in the IDE window header.

    List of run configurations with Edit Configurations selected
  2. Select 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.

Code with a gutter icon and a context menu for a target with "Test using Bazel" selected.

Starlark support

The Bazel plugin provides code completion and navigation in Starlark files:

Code completion suggestions in a Starlark file

Debug Starlark code

  1. Set the breakpoint.

  2. Right-click the corresponding target in the Bazel tool window and select Starlark Debug.

    Debug Starlark code in IntelliJ IDEA
Last modified: 29 November 2024