rules_scala
rules_scala copied to clipboard
strict_deps_mode = error complains about dependencies that aren't referenced
I tried to turn on strict_deps_mode = "error" in my scala_toolchain(), but it complains about dependencies that aren't used directly in my Scala code.
BUILD:
proto_library(
name = "model_proto",
srcs = ["model.proto"],
visibility = ["//visibility:public"],
)
java_proto_library(
name = "model_java_proto",
visibility = ["//visibility:public"],
deps = [
":model_proto",
],
)
scala_library(
name = "scala_class",
srcs = ["ScalaClass.scala"],
visibility = ["//deps-mode:__subpackages__"],
deps = [":model_java_proto"],
)
model.proto:
syntax = "proto3";
package deps_mode;
enum ProtoEnum {
UNKNOWN = 0;
KNOWN = 1;
}
ScalaClass.scala:
package deps_mode
case class ScalaClass(value: Model.ProtoEnum)
Expected bazel build result: success (it builds with strict_deps_mode = "off").
Actual bazel build result: fails with
error: Target '@@com_google_protobuf//java/core:lite_runtime_only' is used but isn't explicitly declared, please add it to the deps.
You can use the following buildozer command:
buildozer 'add deps @@com_google_protobuf//java/core:lite_runtime_only' //deps-mode:scala_class
error: Target '@@com_google_protobuf//java/core:core' is used but isn't explicitly declared, please add it to the deps.
You can use the following buildozer command:
buildozer 'add deps @@com_google_protobuf//java/core:core' //deps-mode:scala_class
2 errors
Build failed
java.lang.RuntimeException: Build failed
at io.bazel.rulesscala.scalac.ScalacInvoker.invokeCompiler(ScalacInvoker.java:55)
at io.bazel.rulesscala.scalac.ScalacWorker.compileScalaSources(ScalacWorker.java:253)
at io.bazel.rulesscala.scalac.ScalacWorker.work(ScalacWorker.java:69)
at io.bazel.rulesscala.worker.Worker.persistentWorkerMain(Worker.java:86)
at io.bazel.rulesscala.worker.Worker.workerMain(Worker.java:39)
at io.bazel.rulesscala.scalac.ScalacWorker.main(ScalacWorker.java:33)
It's kind of surprising, since protobuf//java isn't used explicitly in my Scala code, it's used transitively via ProtoEnum.
Moreover, if I run all of given buildozer commands, then build fails again:
in scala_library rule //deps-mode:scala_class: target '@@com_google_protobuf//java/core:lite_runtime_only' is not visible from target '//deps-mode:scala_class'. Check the visibility declaration of the former target if you think the dependency is legitimate
Although, if I just do buildozer 'add deps @@com_google_protobuf//java/core:core' //deps-mode:scala_class, then build succeeds. But I'd like to avoid adding this dependency everywhere.
Also, strict_deps_mode = error sometimes suggests to add proto_library() dependencies, instead of java_proto_library() dependencies. Couldn't create MVCE yet, though.
Hi, @evis! Thanks for reporting. Could you create a small repo to reproduce your problem?
Regarding java_proto_library deps being incorrectly reported - it's a known issue. It happens because the archive is stamped with incorrect target label from the aspect. The similar issue for scala_proto_library is here for more info: https://github.com/bazelbuild/rules_scala/issues/1234#issuecomment-791628830
Regarding java_proto_library deps being incorrectly reported - it's a known issue
Thanks for your link, found https://github.com/bazelbuild/bazel/issues/4990 here
Could you create a small repo to reproduce your problem?
Yes, I'll try