rules_scala
rules_scala copied to clipboard
Transitive, external protobuf dependencies generate invisible scala targets
I'm not sure if my title makes sense, but let me explain:
I have a proto that imports "google/protobuf/timestamp.proto"
and uses it as part of a message.
So it all comes together a bit like this:
proto_library(
name = "work_item_proto",
srcs = ["work_item.proto"],
strip_import_prefix = "/protobuf",
deps = [
"@com_google_protobuf//:struct_proto",
"@com_google_protobuf//:timestamp_proto",
],
)
scala_proto_library(
name = "work_item_scala_proto",
deps = [":work_item_proto"],
)
The generated scala uses a type com.google.api.timestamp.Timestamp
. This builds fine, but intellij thinks that the type does not exist at all, which is very frustrating (no IntelliSense, when overriding definitions it frequently uses Any
, etc).
I can see a jar being passed to scalac
called bazel-out/darwin-fastbuild/bin/external/com_google_protobuf/timestamp_proto_scalapb.jar
, however, I can't seem to find a bazel target for this jar at all. e.g. if I do a bazel query for the deps of my proto target, nothing like that jar file (timestamp_proto_scalapb.jar
) shows up.
I'm wondering, what is the correct way to handle transitive external dependencies? I think I could create an explicit scala_proto_library
against @com_google_protobuf//:src/google/protobuf/timestamp.proto
, but I don't think the other scala_proto_library
would know to use that and that would result in duplicated code on the classpath.
If there were some bazel target I could depend on that provided the Timestamp scala proto, I think intellij would be able to figure things out.
If we manually flatten transitive proto deps and pass them to scala_proto_library
, intellij correctly finds the generated types, but I'm still curious if there is a better way to go about this.
Hi @andrewhamon,
This is not the answer to your question directly, but I want to share how we handle google protos.
"Well known protos" (like @com_google_protobuf//:timestamp_proto
and others) are precompiled and available in scalapb jar. Therefore we added google protos to blacklisted_protos so that rules_scala will not generate code for them. This is also documented in proto_lang_toolchain
Maybe this will help intellij to resolve correct jar for google protos.