Requirements
IntelliJ IDEA
Version 2024.1 or later (Community or Ultimate Edition)
Bazel Plugin
Official JetBrains Bazel plugin
The project is known to be compatible with IntelliJ IDEA 2024.1 Community Edition as of April 2024.
Installation
Install IntelliJ IDEA
Download and install IntelliJ IDEA (Community Edition is sufficient).
Install Bazel Plugin
- Open IntelliJ IDEA
- Go to Settings/Preferences → Plugins
- Search for “Bazel” in the Marketplace
- Install the Bazel plugin
- Restart IntelliJ IDEA
Install ktfmt Plugin (Optional)
For automatic Kotlin formatting:
- Go to Settings/Preferences → Plugins
- Search for “ktfmt”
- Install the ktfmt plugin
- This will replace the default “Reformat Code” action
Project Setup
Import Bazel Project
- Open IntelliJ IDEA
- Select File → Import Bazel Project
- Choose the repository root as the workspace directory
- Click Next
Configure Project View
IntelliJ will create a
.bazelproject file. Ensure it includes the following configuration:.bazelproject File
The.bazelproject file configures how IntelliJ interacts with your Bazel workspace.
Basic Configuration
Configuration Options
| Option | Description |
|---|---|
directories | Directories to include in the project (. includes all) |
test_sources | Patterns for test source directories |
derive_targets_from_directories | Auto-discover Bazel targets from directories |
additional_languages | Languages requiring special support (e.g., kotlin) |
Advanced Configuration (Optional)
Exclude the
bazel-container-output directory if you use containerized builds to avoid indexing generated files.Code Navigation Features
Once configured, IntelliJ provides powerful navigation capabilities:Go to Definition
Ctrl+Click (Cmd+Click on macOS) on symbols to jump to their definition
Find Usages
Alt+F7 to find all usages of a symbol across the project
Navigate to Class
Ctrl+N (Cmd+O on macOS) to quickly find classes by name
Navigate to File
Ctrl+Shift+N (Cmd+Shift+O on macOS) to find any file
Running and Debugging
Run Bazel Targets
Create Run Configuration
- Right-click on a Bazel target in the project view
- Select Run ‘[target name]’
- IntelliJ automatically creates a run configuration
Debug Bazel Targets
Start Debugging
- Right-click on a Bazel target
- Select Debug ‘[target name]’
- Or press Shift+F9 with an existing run configuration
Testing in IntelliJ
Run Tests
View Test Results
Test results appear in the Run tool window with:- ✅ Passed tests in green
- ❌ Failed tests in red
- Stack traces for failures
- Console output from tests
Formatting and Code Style
Configure ktfmt
If you installed the ktfmt plugin:Enable ktfmt
- Go to Settings/Preferences → Editor → ktfmt Settings
- Check Enable ktfmt
- Select Google (internal) style
Manual Formatting
Format code using:- Ctrl+Alt+L (Cmd+Option+L on macOS) - Format current file
- Ctrl+Alt+Shift+L - Show reformat dialog with options
Code Completion
The Bazel plugin provides intelligent code completion for:- Kotlin/Java/C++ code
- Protocol buffer definitions
- Bazel BUILD files
- Starlark (.bzl) files
If code completion isn’t working, try syncing the project: Bazel → Sync → Sync Project with BUILD Files
Troubleshooting
Sync Issues
If the project isn’t syncing correctly:Missing Dependencies
If IntelliJ can’t resolve dependencies:Performance Issues
For large projects:-
Limit indexed directories in
.bazelproject: -
Increase IntelliJ memory:
- Help → Change Memory Settings
- Set to at least 4096 MB
Alternative: Containerized Development
If your host environment has glibc compatibility issues, you can run IntelliJ inside the build container:Next Steps
Building
Learn how to build the project
Testing
Run and write tests
Dev Standards
Follow code review and commit standards
Contributing
Start contributing to the project