rules_scala icon indicating copy to clipboard operation
rules_scala copied to clipboard

rules_scala module throws error

Open knarukulla opened this issue 6 months ago • 1 comments
trafficstars

I was trying to use bazel modules for rules_scala, it throws below error

bazel_dep(name = "rules_scala", version = "7.0.0") register_toolchains("@rules_scala//testing:testing_toolchain") register_toolchains("@rules_scala//testing:scalatest_toolchain") register_toolchains("@rules_scala//testing:specs2_junit_toolchain") register_toolchains("@rules_scala//testing:junit_toolchain")`

ERROR: no such package '@@rules_scala++scala_deps+rules_scala_toolchains//testing': BUILD file not found in directory 'testing' of external repository @@rules_scala++scala_deps+rules_scala_toolchains. Add a BUILD file to a directory to mark it as a package.
ERROR: /private/var/tmp/_bazel_knarukulla/c061e27a8e8f33c8a7a7866ab26fe72b/external/rules_scala+/testing/BUILD:6:10: no such package '@@rules_scala++scala_deps+rules_scala_toolchains//testing': BUILD file not found in directory 'testing' of external repository @@rules_scala++scala_deps+rules_scala_toolchains. Add a BUILD file to a directory to mark it as a package. and referenced by '@@rules_scala+//testing:specs2_junit_toolchain'
ERROR: /Users/knarukulla/oss/chronon/api/py/BUILD.bazel:37:13: Analysi

knarukulla avatar May 21 '25 21:05 knarukulla

Per the "Getting Started" and "Bzlmod configuration" sections of the README, don't call register_toolchains() directly on the builtin toolchains. You shouldn't need to register the @rules_scala//testing toolchains directly, either, since they're all aliases to a single generated builtin toolchain automatically registered by the rules_scala module.

Instead, use the scala_deps module extension:

scala_deps = use_extension(
    "@rules_scala//scala/extensions:deps.bzl",
    "scala_deps",
)
scala_deps.scala()
scala_deps.scalatest()
scala_deps.specs2()
scala_deps.junit()

It does look like we could add this guidance to the testing documentation.

The only time you'd need to call register_toolchains on any of these toolchains is if another module in the dependency graph registered another toolchain of the same toolchain_type ahead of it, and it caused problems. And in that case, you'd still need to use the scala_deps module extension (though I wouldn't recommend using it this way):

# Following the same snippet from above.
use_repo(scala_deps, "rules_scala_toolchains")

# Use only ONE of the following:
register_toolchains("@rules_scala//testing:testing_toolchain")
register_toolchains("@rules_scala_toolchains//testing/...:all")

mbland avatar May 24 '25 15:05 mbland