-1

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

san
  • 1
  • 3
  • How are you building the gRPC stubs? Can you show the relevant parts of `build.sbt`? – Tim Mar 17 '22 at 07:31
  • @Tim I am using // https://mvnrepository.com/artifact/io.grpc/grpc-protobuf libraryDependencies += "io.grpc" % "grpc-protobuf" % "1.24.1" – san Mar 17 '22 at 07:57
  • I use `AkkaGrpcPlugin` which works well for me. – Tim Mar 17 '22 at 08:17
  • @Tim, oh okay.. but how does the import looking for wrappers.proto or any default proto files works for u? do u need to manually include them in file system or it automatically get included ? – san Mar 17 '22 at 08:23
  • I posted a full answer below, hope it helps. But, yes, includes of standard files works for me using this plugin. – Tim Mar 17 '22 at 09:58

3 Answers3

0

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
)
Ivan Stanislavciuc
  • 7,140
  • 15
  • 18
  • where to include this one? I tried including this in build.sbt but getting error – san Mar 17 '22 at 07:58
  • it needs to be included into project containing your protocol buffer files. also the `scalapb` plugin must be added to `plugins.sbt`. It seems you're missing more things than originally posted in your question – Ivan Stanislavciuc Mar 17 '22 at 08:42
0

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)
Tim
  • 26,753
  • 2
  • 16
  • 29
-1

Thanks everyone for your answers. I really appreciate it.

I was able to solve the dependency issue by

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>unpack</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>unpack</goal>
                    </goals>
                    <configuration>
                        <artifactItems>
                            <artifactItem>
                                 <groupId>com.google.protobuf</groupId>
                                 <artifactId>protobuf-java</artifactId>
                                 <version>3.10.0</version>
                                 <type>jar</type>   
                              <includes>path/to/Files.whatsoever</includes>
<outputDirectory>${project.build.directory}/foldername</outputDirectory>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

This generates the required proto files inside target folder

san
  • 1
  • 3