rules_jvm_external icon indicating copy to clipboard operation
rules_jvm_external copied to clipboard

bzlmod: Consider documenting the need to add --enable_bzlmod to examples

Open acr92 opened this issue 2 years ago • 1 comments

Hello,

I've been playing a bit with Bazel 6, bzlmod and rules_jvm_external over the last two days, and one thing that took me a lot of time to figure out was that it wasn't just enough to put the load() instructions in the BUILD.bazel files, e.g.:

WORKSPACE.bzlmod

bazel_dep(name = "rules_java", version = "5.3.5")

bazel_dep(name = "rules_jvm_external", version = "4.5")

maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
maven.install(
    artifacts = [
        "some.group.id:some.artifact.id:1.2.34",
    ],
)

use_repo(
    maven,
    "maven",
)

BUILD.bazel

load("@rules_jvm_external//:defs.bzl", "artifact")

java_binary(
    name = "app",
    srcs = glob(['src/main/java/**/*.java']),
    deps = [
        artifact("some.group.id:some.artifact.id"),
    ],
)

This would just complain that it couldn't find the repository rules_jvm_external.

I also had to put this into my .bazelrc file:

common --enable_bzlmod

Now I don't yet understand why that's necessary, but as it took a lot of digging for me, and basically tearing down an existing example to get it working, I'm sure that others would encounter the same issue if they were to test out Bazel 6 and bzlmod.

acr92 avatar Dec 27 '22 16:12 acr92

I think the broader issue is that bzlmod usage isn't documented at all yet.

alexeagle avatar Jan 18 '23 00:01 alexeagle