This video introduces the Bazel IntelliJ plugin, an open-source tool maintained by Google that facilitates Bazel project development within the IntelliJ family of IDEs. The demonstration walks through the entire workflow, starting with importing an existing Bazel workspace using highly configurable "project view" settings. It showcases how to define included directories, targets, and additional languages to accurately reflect the project structure. Key functionalities covered include running, debugging, and testing Bazel binaries and test targets directly from the IDE, with support for test coverage and an experimental "First Run" feature for faster incremental Java test reruns. The video also details various synchronization operations—incremental, non-incremental, working set, partial, and directories-only syncs—essential for maintaining consistency between the Bazel build system and the IDE's project state. The plugin aims to provide comprehensive IDE support to streamline development for projects managed by Bazel.
Summarizing the Bazel IntelliJ Plugin: A Comprehensive Guide
0:00 Introduction to Bazel IntelliJ Plugin: This plugin, maintained by Google engineers, allows seamless development of Bazel projects within IntelliJ IDEA, CLion, and other IntelliJ-family IDEs. It can be installed directly from the IDE's marketplace.
0:28 Importing a Bazel Workspace: The process begins by selecting an existing Bazel workspace, demonstrated with a simple Java "greetings" project containing a library and multiple runner packages.
0:57 Defining the Project View: A "Project View" file is crucial for defining which parts of the Bazel project the IDE should import.
1:41 Creating from Scratch: Users can specify directories to include (e.g., . for the entire workspace, or specific paths like hello, greeting-lab) and exclude (using a dash prefix).
2:28 Specifying targets: The targets section lists Bazel build targets (using canonical labels like //hello:greeter) that the plugin uses to build the project during synchronization, resolving dependencies and properties. Targets can also be excluded.
3:09derive_targets_from_directories: An optional feature that automatically attempts to find relevant targets within the specified directories.
3:33additional_languages: Allows specifying languages not supported by default in the chosen IDE (e.g., Kotlin in IntelliJ) to ensure proper indexing.
4:10 Other View Options: Project views can be selected from an existing file, generated for a specific package's build file, or copied from an external source.
4:57 Initial Project Sync: After configuring the project view, an initial sync operation imports the specified directories into the IDE and performs a Bazel build. This build is essential for the plugin to learn about project dependencies and resolve any initial unresolved references in the code.
6:30 Running and Debugging Binaries: The plugin automatically creates run configurations for Bazel binary targets (e.g., java_binary). Users can run them directly from the IDE (via icons next to class names or main methods), add breakpoints, and debug. Run configurations are customizable for passing Bazel flags or specifying a custom Bazel binary.
7:54 Running and Debugging Tests: Similar functionality is available for Bazel test targets. Users can run all tests in a class or individual test methods, and debug them with breakpoints.
8:30 Running Tests with Coverage: The plugin supports running bazel test --coverage and displays the coverage summary directly within the IDE, showing metrics like percentage of lines covered.
8:49 "First Run" for Faster Test Reruns (Experimental): This experimental feature, currently for Java tests only, aims to speed up incremental test reruns. The initial "First Run" executes the test via Bazel, but subsequent runs (if only source files change) invoke Java directly, significantly reducing execution time. Re-syncing via Bazel is necessary if test target dependencies change.
10:07 Synchronization Operations for Project Updates: Various sync types are available and necessary after any modifications to source files, targets, or project structure.
10:35 Incremental Sync (Sync project with build files): Performs a bazel build on all targets in the project view to incrementally update the existing IDE project state.
10:57 Non-Incremental Sync: Ignores the current IDE project state and rebuilds it entirely from scratch, useful for clearing stale artifacts.
11:23 Sync Working Set: Detects modified files and only builds the targets that compile those files, refreshing only the working set.
12:07 Partially Sync: Allows refreshing specific files or directories by right-clicking on them, updating their state in the IDE.
12:40 Sync Directories (Special Type): This sync only imports new directories into the IDE's project tree without performing a bazel build. This might leave symbols unresolved until a subsequent full or partial sync with a build is performed.
14:32 Clean Project Targets: An action to remove stale targets (e.g., those that have been deleted or renamed) from the plugin's internal project state.
15:34 Build Submenu (Compile project/Compile file): These actions run bazel build on all project targets or a specific file's target, respectively, allowing users to check build integrity without altering the plugin's current sync state.
16:13 Project Submenu (Open project view file/Add directory to project): Provides shortcuts to open the active project view file or to add a directory to the project without manual file editing, requiring a subsequent sync to resolve code.
17:11 Community and Resources: The presenter encourages users to consult the plugin's documentation, join the Bazel IntelliJ plugin Slack channel, and attend monthly meetings for support and discussions with maintainers and other users.