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

> **Tip:**
> For a broader introduction to Bazel in IntelliJ IDEA, refer to [Tutorial: Get started with Bazel](tutorial-get-started-with-bazel.html).

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

Procedure: 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](https://resources.jetbrains.com.cn/help/img/idea/2026.2/bazel-tw-icon.png)

Procedure: Search for a target by name

1. In the Bazel tool window, click the search field or press `Ctrl+F` (Windows), `⌘ F` (macOS), `⌘ F` (IntelliJ IDEA Classic (macOS)), `⌘ F` (macOS System Shortcuts), `Ctrl+F` (XWin), `Ctrl+F` (GNOME), `Ctrl+F` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+F` (Sublime Text), `⌘ F` (Sublime Text (macOS)), `Ctrl+F` (NetBeans), `Ctrl+F` (Visual Studio), `⌘ F` (Visual Studio (macOS)), `Ctrl+F` (Eclipse), `Ctrl+F` (Eclipse (macOS)) 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](https://resources.jetbrains.com.cn/help/img/idea/2026.2/bazel-search-targets.png)

> **Tip:**
> You can also use [Search Everywhere](searching-everywhere.html) `Shift Shift` (Windows), `⇧ ⇧` (macOS), `⇧ ⇧` (IntelliJ IDEA Classic (macOS)), `⇧ ⇧` (macOS System Shortcuts), `Shift Shift` (XWin), `Shift Shift` (GNOME), `Shift Shift` (KDE), `Shift Shift` (Emacs), `Shift Shift` (Sublime Text), `⇧ ⇧` (Sublime Text (macOS)), `Shift Shift` (NetBeans), `Ctrl+T` (Visual Studio), `⌘ T` (Visual Studio (macOS)), `Shift Shift` (Eclipse), `⇧ ⇧` (Eclipse (macOS)) for a quick search across the project. This will show Bazel targets along with other items that have a similar name.

Procedure: 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 ![](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app-client.expui.general.filter.svg) 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.

## Navigate to a target and copy its label

Target context actions are available from several places in the IDE:

| Location | Available actions |
| --- | --- |
| Bazel tool window |  Right-click a target and select Jump to BUILD file or Copy Target Label.  |
| Bazel File Targets widget |  Click the widget in the status bar, expand the target, and select Jump to BUILD file or Copy Target Label.  |
| Editor |  In a source file that belongs to a target, right-click and select either action. In a `BUILD` file, right-click a rule name or the value of its `name` argument, then select Copy Target Label.  |
| Editor tab |  Right-click the tab of a source file that belongs to a target and select either action. You can also copy a label from the tab of a `BUILD` file.  |

Use Jump to BUILD file to open the target definition. When IntelliJ IDEA can resolve the exact rule, it opens the corresponding rule call inside the `BUILD` file. Otherwise, it opens the `BUILD` file itself.

Use Copy Target Label to copy the target label, such as `//src/main:app`, to the clipboard.

> **Note:**
> If the current file belongs to more than one target, IntelliJ IDEA asks you to choose the target first.

## 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     > **Tip:** > For information on viewing coverage data in IntelliJ IDEA, refer to [Code coverage](code-coverage.html).    | `*_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](run-debug-configuration.html).

Procedure:

* From the editor: click the ![](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app-client.expui.gutter.run.svg) 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](https://resources.jetbrains.com.cn/help/img/idea/2026.2/run-bazel-target-from-gutter.png)

* 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](https://resources.jetbrains.com.cn/help/img/idea/2026.2/run-bazel-target-from-tw.png)

* From an existing run configuration: pick a saved Bazel run configuration from the [Run widget](new-ui.html#window_header) 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](https://resources.jetbrains.com.cn/help/img/idea/2026.2/bazel-targets-status-bar-widget.png)

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:

Procedure:

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](bazel-project-view.html) go to `Build | Build Project` or press `Ctrl+F9` (Windows), `⌘ F9` (macOS), `⌘ F9` (IntelliJ IDEA Classic (macOS)), `⌘ ⌃ B` (macOS System Shortcuts), `Ctrl+F9` (XWin), `Ctrl+F9` (GNOME), `Ctrl+9` (KDE), `Ctrl+F9` (Emacs), `Ctrl+F9` (Sublime Text), `Ctrl+F9` (Sublime Text (macOS)), `F11` (NetBeans), `F7` (Visual Studio), `F7` (Visual Studio (macOS)), `Ctrl+F9` (Eclipse), `⌘ B` (Eclipse (macOS)).

## Targets' sync settings

For controlling which targets get synced, indexed, and available in the IDE, refer to [Bazel project view](bazel-project-view.html).

