Skip to content

Undefined @@rules_java_builtin repository with --noenable_workspace option #22754

Closed
@ghost

Description

Description of the bug:

It is sometimes necessary to have a WORSPACE file inside a test data directory. This is particularly the case for gazelle tests using the rule gazelle_generation_test.
But when we use a pure bzlmod Bazel project, with --enable_bzlmod and --noenable_workspace options, and without a file WORKSPACE.bzlmod, Bazel fails to visit this tests data directory containing a WORKSPACE file:

ERROR: Failed to load package, for testdata, skipping: error loading package '': Unable to find package for @@rules_java_builtin//toolchains:local_java_repository.bzl: The repository '@@rules_java_builtin' could not be resolved: Repository '@@rules_java_builtin' is not defined.
  • No problem with --enable_workspace option.
  • No problem with an empty WORKSPACE.bzlmod
  • No problem with an empty MODULE.bazel file inside the test data directory (gazelle_generation_test should support this solution).

Which category does this issue belong to?

External Dependency

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

.
├── .bazelrc
├── .bazelversion
├── BUILD.bazel
├── MODULE.bazel
└── testdata
    └── WORKSPACE

.bazelrc

common --enable_bzlmod
common --noenable_workspace
common --lockfile_mode=off

.bazelversion

7.2.0

BUILD.bazel

testfiles = glob(["testdata/**"])
print(testfiles)

MODULE.bazel

module(name = "foo")

$ bazel build :all
WARNING: Target pattern parsing failed.
ERROR: Skipping ':all': while parsing ':all': error loading package '': Unable to find package for @@rules_java_builtin//toolchains:local_java_repository.bzl: The repository '@@rules_java_builtin' could not be resolved: Repository '@@rules_java_builtin' is not defined.
ERROR: while parsing ':all': error loading package '': Unable to find package for @@rules_java_builtin//toolchains:local_java_repository.bzl: The repository '@@rules_java_builtin' could not be resolved: Repository '@@rules_java_builtin' is not defined.
INFO: Elapsed time: 0.023s
INFO: 0 processes.
ERROR: Build did NOT complete successfully

Which operating system are you running Bazel on?

Linux / amd64

What is the output of bazel info release?

release 7.2.0

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 ?

No response

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

Metadata

Assignees

Labels

P1I'll work on this now. (Assignee required)team-ExternalDepsExternal dependency handling, remote repositiories, WORKSPACE file.type: bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions