Skip to main content
Version: 0.6.x

Installing ZIO gRPC

Determining the right version

The version of zio-grpc needs to be compatible with the version of ScalaPB in order to avoid unintended evictions and ensure binary compatibility:

ScalaPBZIO gRPC
0.11.x0.5.x
0.10.x0.4.x

If you are building with sbt, add the following to your project/plugins.sbt:

addSbtPlugin("com.thesamet" % "sbt-protoc" % "1.0.6")

libraryDependencies +=
"com.thesamet.scalapb.zio-grpc" %% "zio-grpc-codegen" % "0.6.0-rc6"

Then, add the following lines to your build.sbt:

PB.targets in Compile := Seq(
scalapb.gen(grpc = true) -> (sourceManaged in Compile).value / "scalapb",
scalapb.zio_grpc.ZioCodeGenerator -> (sourceManaged in Compile).value / "scalapb"
)

libraryDependencies ++= Seq(
"io.grpc" % "grpc-netty" % "1.50.1",
"com.thesamet.scalapb" %% "scalapb-runtime-grpc" % scalapb.compiler.Version.scalapbVersion
)

This configuration will set up the ScalaPB code generator alongside the ZIO gRPC code generator. Upon compilation, the source generator will process all proto files under src/main/protobuf. The ScalaPB generator will generate case classes for all messages as well as methods to serialize and deserialize those messages. The ZIO gRPC code generator will generate code as described in the generated code section.

Generating code using ScalaPBC (CLI)

If you are using ScalaPBC to generate Scala code from the CLI, you can invoke the zio code generator like this:

scalapbc \
--plugin-artifact=com.thesamet.scalapb.zio-grpc:protoc-gen-zio:0.6.0-rc6:default,classifier=unix,ext=sh,type=jar\
-- e2e/src/main/protobuf/service.proto --zio_out=/tmp/out --scala_out=grpc:/tmp/out \
-Ie2e/src/main/protobuf -Ithird_party -Iprotobuf

You will need to add to your project the following libraries:

  • com.thesamet.scalapb::scalapb-runtime-grpc:0.11.14
  • com.thesamet.scalapb.zio-grpc:zio-grpc-core:0.6.0-rc6
  • io.grpc:grpc-netty:1.50.1