Home > database >  Import "google/protobuf/wrappers.proto" was not found scala
Import "google/protobuf/wrappers.proto" was not found scala

Time:03-17

I have a .proto file which Imports google/protobuf/wrappers.proto while I run Scalapbc to generate the relevant scala code out of it it gives Import google/protobuf/wrappers.proto not found error.

as a workaround for now I have kept the wrappers.proto file in file system for now inside --proto_path

But I need to come up with a fix wherein I need add the relevant dependencies in build.sbt / pom.xml to unpack the jar containing default proto files (such as wrappers.proto) before calling Scalapbc

CodePudding user response:

All the required dependencies are provided by scalabp runtime

import sbtprotoc.ProtocPlugin.ProtobufConfig
import scalapb.compiler.Version.scalapbVersion

libraryDependencies   = Seq(
  "com.thesamet.scalapb" %% "scalapb-runtime" % scalapbVersion,
  "com.thesamet.scalapb" %% "scalapb-runtime" % scalapbVersion % ProtobufConfig
)

CodePudding user response:

I uses the AkkaGrpcPugin for sbt which seems to handle all the dependencies.

In plugins.sbt I have

addSbtPlugin("com.lightbend.akka.grpc" % "sbt-akka-grpc" % "1.1.1")

In build.sbt I have

enablePlugins(AkkaGrpcPlugin)

In automatically picks up the files in src/main/protobuf for the project and generates the appropriate stub files. I can import standard files, e.g.

import "google/protobuf/timestamp.proto";

For multi-project builds I use something like this:

lazy val allProjects = (project in file("."))
  .aggregate(util, grpc)

lazy val grpc =
  project
    .in(file("grpc"))
    .settings(
      ???
    )
    .enablePlugins(AkkaGrpcPlugin)

lazy val util =
  project
    .in(file("util"))
    .settings(
      ???
    )
    .dependsOn(grpc)
  • Related