`bazel vendor` does not support offline builds on clean installs (only with no targets?)
- Dominant language
- Java
- Stars
- 25.8k
- Forks
- 4.6k
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 75
Description
### Description of the bug:
The 'vendor' command is supposed to download all required dependencies for a build into a directory, so that builds may be performed with no internet connection. However, when using a vendor directory, Bazel still tries to download things if the output user root (`~/.cache/bazel/_bazel_$USER`) directory does not exist.
This was discussed by @AlexanderAA in the comments to #23243 but not clearly reported as an issue.
### Which category does this issue belong to?
Core
### What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
Create a completely empty Bazel workspace:
echo -n > BUILD
echo -n > MODULE.bazel
echo 8.3.1 > .bazelversion
Run Bazel vendor:
bazelisk vendor --vendor_dir=../vendor //...
Confirm the build succeeds with no internet:
$ HTTP_PROXY=invalid_host HTTPS_PROXY=invalid_host bazelisk build --vendor_dir=../vendor //...
INFO: Found 0 targets...
INFO: Elapsed time: 0.284s, Critical Path: 0.03s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
Delete the output user root:
rm -rf ~/.cache/bazel/_bazel_$USER
Confirm Bazel now tries to download things:
$ HTTP_PROXY=invalid_host HTTPS_PROXY=invalid_host bazelisk build --vendor_dir=../vendor //...
Extracting Bazel installation...
Starting local Bazel server (8.3.1) and connecting to it...
WARNING: Download from https://github.com/protocolbuffers/protobuf/releases/download/v29.0/protobuf-29.0.zip failed: class com.google.devtools.build.lib.bazel.repository.downloader.UnrecoverableHttpException Unknown host: invalid_host
WARNING: Download from https://github.com/bazelbuild/rules_python/releases/download/0.40.0/rules_python-0.40.0.tar.gz failed: class com.google.devtools.build.lib.bazel.repository.downloader.UnrecoverableHttpException Unknown host: invalid_host
WARNING: Download from https://github.com/bazelbuild/rules_java/releases/download/8.12.0/rules_java-8.12.0.tar.gz failed: class com.google.devtools.build.lib.bazel.repository.downloader.UnrecoverableHttpException Unknown host: invalid_host
WARNING: Download from https://github.com/bazelbuild/rules_shell/releases/download/v0.2.0/rules_shell-v0.2.0.tar.gz failed: class com.google.devtools.build.lib.bazel.repository.downloader.UnrecoverableHttpException Unknown host: invalid_host
INFO: Repository rules_python+ instantiated at:
: in
Repository rule http_archive defined at:
/home/tommewett/.cache/bazel/_bazel_tommewett/883ee1d6948bd4f9c0c635b1d6df68cf/external/bazel_tools/tools/build_defs/repo/http.bzl:394:31: in
INFO: Repository rules_java+ instantiated at:
: in
Repository rule http_archive defined at:
/home/tommewett/.cache/bazel/_bazel_tommewett/883ee1d6948bd4f9c0c635b1d6df68cf/external/bazel_tools/tools/build_defs/repo/http.bzl:394:31: in
INFO: Repository rules_shell+ instantiated at:
: in
Repository rule http_archive defined at:
/home/tommewett/.cache/bazel/_bazel_tommewett/883ee1d6948bd4f9c0c635b1d6df68cf/external/bazel_tools/tools/build_defs/repo/http.bzl:394:31: in
INFO: Repository protobuf+ instantiated at:
: in
Repository rule http_archive defined at:
/home/tommewett/.cache/bazel/_bazel_tommewett/883ee1d6948bd4f9c0c635b1d6df68cf/external/bazel_tools/tools/build_defs/repo/http.bzl:394:31: in
ERROR: /home/tommewett/.cache/bazel/_bazel_tommewett/883ee1d6948bd4f9c0c635b1d6df68cf/external/bazel_tools/tools/build_defs/repo/http.bzl:139:45: An error occurred during the fetch of repository 'rules_python+':
Traceback (most recent call last):
File "/home/tommewett/.cache/bazel/_bazel_tommewett/883ee1d6948bd4f9c0c635b1d6df68cf/external/bazel_tools/tools/build_defs/repo/http.bzl", line 139, column 45, in _http_archive_impl
download_info = ctx.download_and_extract(
Error in download_and_extract: java.io.IOException: Error downloading [https://github.com/bazelbuild/rules_python/releases/download/0.40.0/rules_python-0.40.0.tar.gz] to /home/tommewett/.cache/bazel/_bazel_tommewett/883ee1d6948bd4f9c0c635b1d6df68cf/external/rules_python+/temp8577769178235868856/rules_python-0.40.0.tar.gz: Unknown host: invalid_host
### Which operating system are you running Bazel on?
Ubuntu 24.04.2 LTS
### What is the output of `bazel info release`?
release 8.3.1
### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.
_No response_
### What's the output of `git remote get-url origin; git rev-parse HEAD` ?
```text
```
### If this is a regression, please try to identify the Bazel commit where the bug was introduced with bazelisk --bisect.
_No response_
### Have you found anything relevant by searching the web?
_No response_
### Any other information, logs, or outputs that you want to share?
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.