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

1.4k Views Asked by At

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

3

There are 3 best solutions below

0
On

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)
2
On

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
)
1
On

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