scalapb/ScalaPB

google/protobuf/empty.proto: File not found.

Closed this issue · 1 comments

I am trying to factor out my Protobuf stuff into a SBT submodule. Here is my build.sbt for that:

import Versions.{commonProtosVersion, grpcVersion, protobufVersion}

name := "processingconfig"

PB.protocVersion := protobufVersion

Compile / PB.targets := Seq(
//  PB.gens.java(protobufVersion) -> (Compile / sourceManaged).value,
  scalapb.gen(javaConversions = true) -> (Compile / sourceManaged).value / "scalapb",
//  PB.gens.plugin("grpc-java") -> (Compile / sourceManaged).value,
  )

Compile / PB.protoSources := Seq(
  sourceDirectory.value / "main" / "protobuf" / "processingconfig" / "protocol"
  )

libraryDependencies += "com.google.api.grpc" % "proto-google-common-protos" % commonProtosVersion intransitive()
libraryDependencies += "io.grpc" % "protoc-gen-grpc-java" % grpcVersion asProtocPlugin()
libraryDependencies += "io.grpc" % "grpc-protobuf" % grpcVersion
libraryDependencies += "io.grpc" % "grpc-netty-shaded" % grpcVersion
libraryDependencies += "io.grpc" % "grpc-core" % grpcVersion
libraryDependencies += "io.grpc" % "grpc-stub" % grpcVersion

When I try to build this, it complains:

google/protobuf/empty.proto: File not found.
ProcessingConfig.proto:5:1: Import "google/protobuf/empty.proto" was not found or had errors.
ProcessingConfig.proto:228:21: "google.protobuf.Empty" is not defined.

How can I reference the common protocols correctly?

Edit: These are my versions:

  lazy val commonProtosVersion = "2.23.0"
  lazy val grpcVersion         = "1.61.0"
  lazy val protobufVersion     = "3.25.2"

Followup

I now added the Google Protobuf source code as a Git Submodule to my project and did something like this:

Compile / PB.includePaths ++= Seq(
  baseDirectory.value.getParentFile / "external" / "protobuf" / "src"
  )

However I think this is a workaround. Or is this the way it actually should be done?

See the installation notes https://scalapb.github.io/docs/installation#installing-in-sbt-recommended:

libraryDependencies ++= Seq(
    "com.thesamet.scalapb" %% "scalapb-runtime" % scalapb.compiler.Version.scalapbVersion % "protobuf"
)