The following README and project shows how you can use monix-grpc with sbt.
You can install monix-grpc by:
-
Enabling
sbt-protoc
in your build and adding Monix's grpc code generator.addSbtPlugin("com.thesamet" % "sbt-protoc" % "1.0.4") libraryDependencies += "me.vican.jorge" %% "monix-grpc-codegen" % "0.0.0+45-79d91dec+20210625-1618"
-
Scope the following settings for every sbt project where you have protobuf files in
src/main/protobuf
.PB.targets in Compile := Seq( scalapb.gen(grpc = false) -> (sourceManaged in Compile).value / "scalapb", monix.grpc.codegen.GrpcCodeGenerator -> (sourceManaged in Compile).value / "scalapb" )
-
Add
scalapb-runtime-grpc
runtime to your library dependencies so that the generated code works.libraryDependencies ++= Seq( "com.thesamet.scalapb" %% "scalapb-runtime-grpc" % scalapb.compiler.Version.scalapbVersion )
-
If you do not already have
io.grpc.grpc-netty
in your classpath, add it so that you can use a concrete grpc-java channel and server APIs.libraryDependencies ++= Seq( "io.grpc" % "grpc-netty" % "1.39.0" )
-
After that, compiling and running your application will trigger the protobuf code generation and the generated code will be accessible from your classpath. The following protobuf code:
syntax = "proto3"; package demo; message Request { string hello = 1; } message Response { string world = 1; } service TestService { rpc Unary(Request) returns (Response); }
will generate an abstract trait
demo.testservice.TestServiceApi
that you can implement and pass to the grpc-java API.