This video provides an introductory walkthrough of the Bazel plugin for IntelliJ-based IDEs, presented by a Google engineer from the maintenance team. The tutorial covers the entire workflow for developing Bazel projects within the IDE, starting with installation from the marketplace and importing a project. A central concept is the "project view" file, a configuration file that specifies which directories and targets to include, how to handle dependencies, and which programming languages to support. The video demonstrates how to run, debug, and get code coverage for both binaries and tests directly within the IDE. It also details the various types of sync operations—incremental, non-incremental, working set, and partial—which are crucial for keeping the IDE's understanding of the project aligned with changes in the Bazel build files.
A Guide to Using the Bazel IntelliJ Plugin
0:29 Getting Started: The plugin can be installed from the IntelliJ marketplace. Once installed, you can import a project by selecting its workspace directory through the "Import Bazel Project" option on the welcome screen.
1:30 Configuring with Project View: The core of the import process is the "project view" file. This file defines which parts of your project are imported into the IDE, including specific directories and targets. You can create this file from scratch, use an existing one, or generate one for a specific package.
3:06 Automatic Target Discovery: Instead of listing all targets manually, you can set derive_targets_from_directories to true in the project view. This instructs the plugin to automatically find and sync the relevant Bazel targets within the specified directories.
5:44 The Initial Sync Process: After configuring the project view, the plugin performs an initial sync. It first imports the selected directories and then runs a bazel build on the specified targets to resolve all code dependencies and external libraries, which fixes any "unresolved reference" errors in the IDE.
6:44 Running & Debugging Binaries: The plugin automatically creates run/debug configurations for Bazel binaries (e.g., java_binary). You can run or debug code directly from icons next to the main class or method, add breakpoints, and step through code.
7:59 Executing Tests: Similar support is available for test targets. You can run or debug an entire test class or individual test methods. The plugin also supports running tests with coverage to generate a code coverage report.
8:49 Fast Run for Java Tests: An experimental "Fast Run" feature aims to accelerate incremental test runs. The first run uses Bazel, but subsequent runs for unchanged code can use Java directly, resulting in a significant speed-up.
10:35 Sync Operations Explained: When you modify Bazel BUILD files or the project structure, a sync is required to update the IDE. The plugin offers several types of syncs:
Incremental Sync: The default sync, which runs a build and updates the existing IDE project state.
Non-Incremental Sync: Wipes the existing state and rebuilds it from scratch. Useful for fixing issues with stale or removed artifacts.
Working Set Sync (11:23): A faster sync that only builds targets corresponding to the files you have recently modified.
Partial Sync (12:07): A targeted sync that refreshes a single file or directory, ideal for quickly resolving newly added code.
15:34 Build-Only Actions: The Build menu allows you to run bazel build on your project or a specific file (Compile Project/Compile File). This validates that your code builds correctly without changing the IDE's sync state.
16:13 Managing Project Scope: You can easily add new directories to your project from the Bazel > Project menu, which automatically updates the project view file and triggers a sync to import the new files.
17:19 Community and Support: The presenter encourages users to consult the official documentation and join the Bazel IntelliJ plugin Slack channel to ask questions and engage with maintainers.