
Identify flaky test
To detect flaky tests, tests should not be cached (--cache_test_results=no) and rerun multiple times (--runs_per_test).
bazel test --compilation_mode=opt --cache_test_results=no --runs_per_test=20 -- //some_targets/...
Workspace files
Since Bzlmod WORKSPACE files are no longer needed, but sometimes tooling still requires them. Therefore, the recommendation is to keep an empty WORKSPACE or WORKSPACE.bazel file to keep tooling happy. Add to your WORKSPACE file a comment like this:
# Only left here for compatibility with tools that don't recognize MODULE.bazel yet.
With the advent of Bazel 9, WORKSPACE files are no longer supported by Bazel. Once the LTS of Bazel 8 ends, it’s a good time to get rid of all WORKSPACE files. Bazel 8 security support ends at 31 Dec 2027. Latest that date all WORKSPACE files can be removed.
Buildifier
Buildifier can be used to reformat build files, e.g., buildifier BUILD.bazel will reformat the BUILD.bazel file. If you want to do it recursive for all Bazel-related files (e.g. MODULE.bazel, *.bzl), you can run builifier -r some_folder or builifier -r . (whereas . marks the current folder). When running builifier with -lint=fix, it also applies some fixes to build files — e.g., introducing load statements for cc_binary, etc., when they are missing.
buildifier -lint=fix -r .
Bazel Central Registry
Hashes
When a new version of {fmt} is released and I want to use it I usally add it first to the Bazel Central Registry. Since between older and new versions usually there are no big changes, I just copy the latest version in the BCR, e.g. 12.0.0 and rename it to 12.1.0. I do than change the source.json file, update the version number in the MODULE.bazel file and bump depedencies (e.g. rules_cc). The source.json file contains also a hash of the referenced archive (source code of {fmt}), BUILD.bazel, and MODULE.bazel. Also metadata.json has to be extended with the version. This all can done by running the command:
bazel run //tools:update_integrity - fmt
Overlay
The overlay feature is also very nice — it allows you to overlay BUILD.bazel and MODULE.bazel files. Since you need the MODULE.bazel in the current version folder and the overlay folder you can create a symlink via ln -s ../MODULE.bazel MODULE.bazel.