Module Management
init, mod add, mod rm, mod list, mod info, mod update, mod outdated, mod search, mod sync
bz provides commands for managing Bazel module dependencies, analyzing your dependency graph, scanning for security issues, and preparing for offline/air-gapped environments.
These flags are available for all commands:
| Flag | Description |
|---|---|
-q, --quiet | Reduce output, only show errors and essential info |
--no-color | Disable colored output (auto-detected when not a TTY) |
--offline | Disable all network access, use cache only |
--prefer-offline | Prefer cached data, fallback to network if needed |
--registry <url> | Override the default registry URL |
-h, --help | Show help for any command |
-v, --version | Show version information (on root command) |
bz mod list --quiet # minimal outputbz mod info rules_go --no-color # no ANSI colorsbz mod list --offline # cache onlybz mod outdated --prefer-offline # cache firstbz mod search --registry=https://my.registry rules_goModule Management
init, mod add, mod rm, mod list, mod info, mod update, mod outdated, mod search, mod sync
Dependency Analysis
mod graph, mod stats, mod why
Security & Compliance
audit, mod licenses, sbom
Cache & Offline
cache download, cache stats, cache verify, cache clear
Utilities
doctor, registry ping, completion, version
bz initInitialize a new Bazel module by creating a MODULE.bazel file.
bz init # use directory name as module namebz init --name=my_module # set module namebz init --name=foo --version=1.0.0bz init --force # overwrite existing MODULE.bazel| Flag | Description |
|---|---|
--name | Module name (defaults to directory name) |
--version | Initial module version (default: 0.0.0) |
--force | Overwrite existing MODULE.bazel |
bz mod addAdd one or more dependencies to MODULE.bazel.
bz mod add rules_go@0.50.1bz mod add rules_go@0.50.1 rules_python@0.35.0bz mod add --dev gazelle@0.38.0| Flag | Description |
|---|---|
--dev | Add as a dev dependency |
bz mod rmRemove dependencies from MODULE.bazel.
bz mod rm rules_gobz mod rm rules_go rules_pythonbz mod rm --dry-run rules_go| Flag | Description |
|---|---|
--dry-run | Show what would be removed without making changes |
bz mod listList dependencies in MODULE.bazel.
bz mod listbz mod list --all # include extensions, overrides, toolchainsbz mod list --json| Flag | Description |
|---|---|
-a, --all | Show all contents (extensions, overrides, etc.) |
--json | Output as JSON |
JSON output format:
{ "dependencies": [ {"name": "rules_go", "version": "0.50.1", "dev_dependency": false}, {"name": "gazelle", "version": "0.38.0", "dev_dependency": true} ]}bz mod infoShow information about a module from the registry.
bz mod info rules_go # show metadata and all versionsbz mod info rules_go@0.50.1 # show specific version detailsbz mod info rules_go --json| Flag | Description |
|---|---|
--json | Output as JSON |
bz mod updateUpdate dependencies to latest stable versions.
bz mod update # update all dependenciesbz mod update rules_go # update specific modulebz mod update rules_go gazelle # update multiple modulesbz mod update --dry-run # preview changes| Flag | Description |
|---|---|
--dry-run | Show what would be updated without making changes |
bz mod outdatedCheck all dependencies for newer versions.
bz mod outdatedbz mod outdated --json| Flag | Description |
|---|---|
--json | Output as JSON |
Example output:
Module Current Latest------ ------- ------rules_go 0.49.0 0.50.1gazelle 0.37.0 0.38.0bz mod searchSearch for modules in the registry.
bz mod search rules_gobz mod search pythonbz mod search protobuf -v # show version infobz mod search grpc -n 5 # limit to 5 results| Flag | Description |
|---|---|
-v, --verbose | Show version info for each result |
-n, --limit | Maximum number of results (default: 20) |
bz mod syncSync modules from a source registry to a destination based on a workflow defined in bz.star configuration.
bz mod sync mirror-essential # run a workflowbz mod sync mirror-essential --dry-run # preview what would be syncedbz mod sync --list # list available workflows| Flag | Description |
|---|---|
-c, --config | Path to config file (default: bz.star) |
--dry-run | Show what would be synced without making changes |
-l, --list | List available workflows |
--modules | Override modules to sync (comma-separated) |
-v, --verbose | Print detailed progress |
See Configuration for details on writing Starlark sync workflows.
bz mod graphDisplay the dependency graph of your Bazel module.
bz mod graph # ASCII tree outputbz mod graph --format=dot # Graphviz DOT formatbz mod graph --format=mermaid # Mermaid diagrambz mod graph --format=json # JSON structurebz mod graph --json # shortcut for --format=jsonbz mod graph --depth=2 # limit depth| Flag | Description |
|---|---|
--format | Output format: ascii (default), dot, json, mermaid |
--json | Shortcut for --format=json |
--depth | Maximum depth to traverse (0 = unlimited) |
Example ASCII output:
my_project├── rules_go@0.50.1│ ├── bazel_skylib@1.5.0│ └── platforms@0.0.8└── rules_python@0.35.0 └── bazel_skylib@1.5.0Generate visualization:
bz mod graph --format=dot | dot -Tpng -o deps.pngbz mod statsDisplay statistics about module dependencies.
bz mod statsbz mod stats --json| Flag | Description |
|---|---|
--json | Output as JSON |
Example output:
Dependency Statistics: Direct dependencies: 5 Transitive dependencies: 12 Total modules: 17 Max depth: 4 Dev dependencies: 2bz mod whyShow the dependency path(s) that bring a module into your project.
bz mod why protobuf # why is protobuf included?bz mod why protobuf --all # show all paths, not just shortestbz mod why protobuf --json| Flag | Description |
|---|---|
--all | Show all paths (default: shortest paths only) |
--json | Output as JSON |
Example output:
protobuf is a direct dependency
protobuf is required by: my_project -> rules_go@0.50.1 -> protobuf@25.3 my_project -> protobuf@25.3bz auditScan dependencies for security vulnerabilities using the OSV database.
bz audit # scan all dependenciesbz audit --json # output as JSONbz audit --severity=high # only high/critical vulnerabilitiesbz audit --fix # show suggested updatesbz audit --ecosystem=Go # specify ecosystem manually| Flag | Description |
|---|---|
--json | Output as JSON |
--severity | Minimum severity to report: critical, high, medium, low |
--fix | Show suggested updates to fix vulnerabilities |
--ecosystem | OSV ecosystem to query (e.g., Go, PyPI, crates.io, npm, Maven) |
Example output:
Module Version ID Severity Summary------ ------- -- -------- -------protobuf 25.3 GHSA-xxxx-xxxx HIGH Buffer overflow in...
Suggested fixes: bz mod update protobuf --version=25.4The command returns a non-zero exit code if vulnerabilities are found.
bz mod licensesDisplay license information for all dependencies.
bz mod licenses # list all licensesbz mod licenses --json # output as JSONbz mod licenses --summary # show license counts onlybz mod licenses --check --deny=GPL-3.0 # check for denied licensesbz mod licenses --check --allow=MIT,Apache-2.0| Flag | Description |
|---|---|
--json | Output as JSON |
--summary | Show license summary only |
--check | Check licenses against policy (requires --allow or --deny) |
--allow | Comma-separated list of allowed licenses |
--deny | Comma-separated list of denied licenses |
Example output:
Module Version License------ ------- -------bazel_skylib 1.5.0 Apache-2.0rules_go 0.50.1 Apache-2.0rules_python 0.35.0 Apache-2.0
Summary: 3 Apache-2.0Policy checking:
# Fail if any GPL licenses are foundbz mod licenses --check --deny=GPL-2.0,GPL-3.0,LGPL-3.0
# Only allow specific licensesbz mod licenses --check --allow=MIT,Apache-2.0,BSD-3-Clausebz sbomGenerate a Software Bill of Materials (SBOM) for your Bazel module.
bz sbom # SPDX 2.3 JSON to stdoutbz sbom --format=cyclonedx # CycloneDX 1.4 JSONbz sbom --output=sbom.json # write to filebz sbom --include-transitive=false| Flag | Description |
|---|---|
--format | Output format: spdx (default), cyclonedx |
--output | Output file path (default: stdout) |
--include-transitive | Include transitive dependencies (default: true) |
--registry | Registry URL |
Supported formats:
For air-gapped environments, bz provides cache management commands.
bz cache downloadDownload modules and their transitive dependencies to the local cache.
bz cache download # cache deps from MODULE.bazelbz cache download rules_go gazelle # cache specific modulesbz cache download rules_go@0.50.1 # cache specific versionbz cache download --all # cache ALL modules (large!)| Flag | Description |
|---|---|
--all | Download ALL modules from registry (warning: very large) |
--json | Output as JSON |
--registry | Registry URL to download from |
--cache-dir | Cache directory (default: ~/.cache/bz) |
bz cache statsShow statistics about the local module cache.
bz cache statsbz cache stats --jsonbz cache stats --cache-dir=/path/to/cache| Flag | Description |
|---|---|
--json | Output as JSON |
--cache-dir | Cache directory (default: ~/.cache/bz) |
Example output:
Cache directory: /home/user/.cache/bzTotal modules: 15Total versions: 42Total size: 12.5 MBLast updated: 2024-01-15 10:30:00bz cache verifyVerify that the local cache contains all dependencies required for offline use.
bz cache verifybz cache verify --jsonbz cache verify --cache-dir=/path/to/cache| Flag | Description |
|---|---|
--json | Output as JSON |
--cache-dir | Cache directory (default: ~/.cache/bz) |
Example output:
Verifying cache for MODULE.bazel dependencies...
✓ rules_go@0.50.1 ✓ rules_python@0.35.0 ✗ gazelle@0.38.0 (missing)
Cache is INCOMPLETE. Run 'bz cache download' to fix.Returns non-zero exit code if cache is incomplete.
bz cache clearClear the local module cache.
bz cache clear # clear all (with confirmation)bz cache clear --force # skip confirmationbz cache clear rules_go # clear specific modulebz cache clear --json| Flag | Description |
|---|---|
-f, --force | Skip confirmation prompt |
--json | Output as JSON |
--cache-dir | Cache directory (default: ~/.cache/bz) |
bz doctorCheck Bazel/bzlmod setup and diagnose common issues.
bz doctorbz doctor --json| Flag | Description |
|---|---|
--json | Output as JSON |
Checks performed:
Example output:
Checking Bazel setup...
✓ Bazel installed (7.0.0)✓ MODULE.bazel found✓ .bazelversion found (7.0.0)✓ Bzlmod enabled (default in Bazel 7+)✓ Registry reachable (bcr.bazel.build)
All checks passed!bz registry pingTest registry connectivity.
bz registry ping # check default BCRbz registry ping https://my.registry # check specific registrybz registry ping --json| Flag | Description |
|---|---|
--json | Output as JSON |
bz completionGenerate shell completion scripts.
# Linuxbz completion bash > /etc/bash_completion.d/bz
# macOS (Homebrew)bz completion bash > $(brew --prefix)/etc/bash_completion.d/bz# Enable completion if not alreadyecho "autoload -U compinit; compinit" >> ~/.zshrc
# Add completionbz completion zsh > "${fpath[1]}/_bz"bz completion fish > ~/.config/fish/completions/bz.fish# Load for current sessionbz completion powershell | Out-String | Invoke-Expression
# Load for every sessionbz completion powershell >> $PROFILEbz versionPrint version information.
bz versionbz version --json| Flag | Description |
|---|---|
--json | Output as JSON |
JSON output:
{ "version": "0.5.0", "commit": "abc1234", "date": "2024-01-15T10:30:00Z"}| Code | Description |
|---|---|
| 0 | Success |
| 1 | General error (command failed, invalid arguments, etc.) |
Commands that perform checks (audit, cache verify, mod licenses --check) return non-zero exit codes when issues are found, making them suitable for CI/CD pipelines.
| Variable | Description |
|---|---|
BZ_OFFLINE | Enable offline mode (1, true, yes) |
BZ_PREFER_OFFLINE | Enable prefer-offline mode |
BZ_REGISTRY | Default registry URL |
BZ_CACHE_DIR | Cache directory path |
BZ_DISABLE_COMMANDS | Disable specific commands (comma-separated) |
See Configuration for full configuration options.