IntelliJ IDEA 2026.1 Help

Bazel targets

A Bazel target is a unit that Bazel can build, run, or test. Targets are declared as rule calls inside BUILD or BUILD.bazel files and are identified by a label like //src/main:app, where //src/main is the package and app is the target name.

The main target kinds are:

  • Binary (rules ending in _binary) produce an executable that can be run or debugged.

  • Test (rules ending in _test) produce runnable tests that can also be executed with coverage.

  • Library and other non-executable rules. These can only be built and are consumed as dependencies of binary or test targets.

Find a target

The Bazel tool window lists every target in the project. It is the main place to browse, search for, and interact with the targets. Use it when you are looking for a specific target but do not have a source file or BUILD file open yet.

Open the Bazel tool window

In the right sidebar, click the Bazel icon. Alternatively, select View | Tool Windows | Bazel from the main menu.

Bazel tool window icon on the right sidebar

    Search for a target by name

    1. In the Bazel tool window, click the search field or press Ctrl+F to focus it.

    2. Start typing part of a target label. The tree filters to targets whose labels match the query.

      The search field in the Bazel tool window filtering the target tree

    Filter targets by kind

    When you are looking specifically for runnable or testable targets, you can filter the tree to hide irrelevant ones.

    1. In the Bazel tool window, click Filter on the toolbar.

    2. Select one of the options:

      • All targets (default)

      • Runnable only – keep only *_binary targets.

      • Testable only – keep only *_test targets.

    Run, test, build, and debug a target

    Different kinds of targets have different associated actions:

    Action

    Applies to

    Run

    *_binary targets

    Test

    *_test targets

    Debug

    *_binary and *_test targets

    Build

    Any target, including libraries

    Run with Coverage

    *_test targets

    IntelliJ IDEA creates a temporary Bazel run configuration for each run, test, or debug action. For saving, renaming, and configuring run configurations, refer to Run/debug configurations.

    • From the editor: click the gutter icon next to the relevant code element, such as main() entry point the or a rule call in a BUILD file, then select the action.

      The gutter icon popup with the Run action selected
    • From the Bazel tool window: right-click a target and select the action. Alternatively, double-click the target: this runs executable targets (binary and test) and builds non-executable ones.

      The Bazel tool window with the Run context menu item selected
    • From an existing run configuration: pick a saved Bazel run configuration from the Run widget and select Run or Debug.

    • From the Bazel File Targets widget: with a file associated with a target open in the editor, click the widget in the status bar, expand the target, and select the action.

      The Bazel file targets widget in the status bar

      There can be more than one target associated with a given file.

      If the Bazel File Targets widget is inactive, it means that the plugin could not map the current editor file to any Bazel target. Check the following:

      • The open file belongs to a synced Bazel target

      • Documentation, scripts, generated files, and other sources that are not referenced by any target's srcs stay inactive even when opened.

      • The project is synced.

        The widget reads target information from the last project sync. After you add a file to srcs or edit a BUILD file, resync the project so the widget picks up the change.

    Run all tests under a directory

    To run or cover multiple test targets at once:

    1. In the Bazel tool window, locate the directory that contains the test targets.

    2. Right-click the directory node and select Run All Tests or Run All Tests with Coverage respectively.

      IntelliJ IDEA runs every *_test target under that directory and merges the results.

    Build an entire project

    To build the selected project view go to Build | Build Project or press Ctrl+F9.

    Targets' sync settings

    For controlling which targets get synced, indexed, and available in the IDE, refer to Bazel project view.

    21 April 2026