.bazelproject file reference
A project view file is split into named sections and uses a Python-like format with two spaces indentation.
File and section syntax
The content after
#until the end of the line is treated as a comment.Section headers start at the beginning of a line and use the
name: bodyorname bodyformat. Both a space or a colon are acceptable after a section name.Section body extends until the next section header.
Section types
All named sections belong to one of the following types:
Single value sections: one Boolean, Int, Path, or String value, for example:
derive_targets_from_directories: true import_depth 2List sections: multiple values separated with a space or a newline, for example:
build_flags: --config=ci --cxxopt=-O2Excludable list sections: multiple values separated with a space or a newline; entries starting with
-are excluded. For example:targets: //app:all -//app:tests
Repeating sections
Sections can appear multiple times. If that happens, the following resolution rules apply:
Single-value sections: the last occurrence wins.
List sections: the sections are merged in the order of appearance.
Excludable list sections: like with regular list sections, both included and excluded lists are merged in the order of appearance.
Imports
A project view can import other project views using import and try_import.
import path/to/file.bazelprojectRequired import. If the file cannot be found, the project view is not considered valid.
try_import path/to/optional.bazelprojectOptional import. If the file cannot be found, the project view is still valid without importing the other project view.
IntelliJ IDEA parses all import entries first, then all try_import entries in the order they appear in the file. After the imports, the current file's own sections are processed.
You can use multiple imports in a project view. In this case, the imported list sections (for example, targets) are merged and single-value sections (for example, bazel_binary) override the previously encountered ones.
Sections reference
This section contains the complete list of available sections grouped by type. For the list of section types and their syntax, refer to the Section types chapter.
Excludable list sections
- targets (List<Path>)
A set of Bazel targets to include in the import. Supports the recursive wildcard for packages (
/...). The more targets you have, the slower your IDE experience might be.Example:
targets: //install/src/main/kotlin/org/jetbrains/bazel/install //executioncontext/projectview/... -//executioncontext/projectview/src/main/kotlin/org/jetbrains/bazel/projectview/parser/...- directories (List<Path>)
The directories to be mapped into Bazel targets. Can be used with derive_targets_from_directories to automatically discover the relevant targets by scanning the specified directories.
Example:
directories: install/src/main/kotlin/org/jetbrains/bazel/install executioncontext/projectview/ -executioncontext/projectview/src/main/kotlin/org/jetbrains/bazel/projectview/parser
List sections
- build_flags (List<String>)
A set of Bazel flags that is passed with all Bazel command invocations. By default, no flags are passed.
Example:
build_flags: --define=ij_product=intellij-latest- sync_flags (List<String>)
A set of Bazel flags that is passed with Bazel command invocations during sync. By default, no flags are passed.
Example:
sync_flags: --define=ij_product=intellij-latest- debug_flags (List<String>)
A set of Bazel flags that is passed to
bazel runin debug mode.Example:
debug_flags: --cxxopt=-g- enabled_rules (List<String>)
Explicitly declares which external Bazel rulesets should be enabled for your project and overrides auto-detection, which can be incomplete for some setups.
The plugin also enables the rulesets that a listed ruleset needs, such as
rules_kotlinaddsrules_java.Example:
enabled_rules: rules_java rules_kotlin- import_run_configurations (List<Path>)
A list of XML files to import as run configurations during Bazel sync.
Example:
import_run_configurations: tools/intellij/run_application.xml tools/intellij/run_tests.xml- index (List<String>)
A list of glob patterns for files to index inside directories, in addition to the sources, resources, and libraries defined by the project.
A pattern without a slash matches a file name in any directory, for example,
package.jsonor*.xml.A pattern with a slash matches a workspace-relative path prefix, for example,
docs/*.*indexes all files insidedirectories.
Example:
index: *.xml package.json docs/*- index_additional_files_in_directories (List<String>)
This section is deprecated. Use index instead. It accepts the same patterns.
Single-value sections
- bazel_binary (Path)
Path to Bazel, which will be used on the server for operations such as building a project or executing a Bazel query. If not specified, the server will use the binary from the $PATH variable.
Example:
bazel_binary: /usr/local/bin/bazel- derive_targets_from_directories (Boolean)
Specifies if targets should be derived from the directories in the
directoriessection. By default, targets are not derived (false), but the directories are not excluded from the project view.Example:
derive_targets_from_directories: true- import_depth (Int)
Specifies how many levels of Bazel targets' dependencies should be imported as modules. Only the targets that are present in the workspace are imported. You can use a negative value to import all transitive dependencies. The default is
-1, meaning that all transitive context is included.Example:
import_depth: 1- allow_manual_targets_sync (Boolean)
Allow syncing targets tagged as manual. By default (
false), manual-only targets are skipped.Example:
allow_manual_targets_sync: trueAllows splitting Bazel sync/build into smaller batches, also referred to as shards, instead of executing a single sync/build. This helps avoid Bazel running out of memory and reduce issues like overly long command lines when syncing large sets of targets. The default is
falsebecause of a potential memory leak issue with Bazel.Example:
shard_sync: true- target_shard_size (Int)
Specifies the number of targets to be built in a shard. The default is
1000Example:
target_shard_size: 500Specifies the strategy used to shard the list of original targets. Used in combination with shard_sync. The default is
QUERY_AND_SHARD.The following values are possible:
EXPAND_AND_SHARD: expand wildcard targets to package targets, query single targets, then shard to batchesQUERY_AND_SHARD: query single targets from the given list of targets without expanding, then shard to batchesSHARD_ONLY: split unexpanded wildcard targets into batches
Example:
sharding_approach: EXPAND_AND_SHARDBoth
EXPAND_AND_SHARDandexpand_and_shardare accepted.- gazelle_target (String)
Path to the Gazelle target to run automatically at the start of each Bazel sync.
If specified, IntelliJ IDEA runs the target to update or generates BUILD files for the directories included in the project view before collecting targets and indexing sources.
Example:
gazelle_target: //tools/gazelle:gazelle- index_all_files_in_directories (Boolean)
This section is deprecated. To index all files inside directories, use index with the
*pattern instead.index: *- run_config_run_with_bazel (Boolean)
Controls whether run configurations execute using Bazel (
bazel run/bazel test) or through --script_path.When enabled, Bazel handles the full execution, which allows you to benefit from Bazel's test result caching and remote build execution (RBE). The trade-off is that Bazel acquires a workspace lock during execution, so you cannot run multiple run configurations in parallel.
When disabled, IntelliJ IDEA compiles the target through Bazel but launches the resulting binary directly, bypassing the Bazel lock.
The default is
true.Example:
run_config_run_with_bazel: false