I stumbled upon this Akka grpc tutorial which suggests that we can create a jar from a project that has .proto file under src/main/proto and add it as a dependency in client and server projects to build their respective stubs.
libraryDependencies += "com.example" %% "my-grpc-service" % "1.0.0" % "protobuf-src"
But this doesn't seem to work!! Are there any example projects that demonstrates how this would work in action? How can we externalize protobuf sources and use the same in a jvm based project?
I was able to figure out how to externalise protobuf files properly as per suggestion from akka-grpc docs.
The problem was that I was not adding
sbt-akka-grpcplugin required by sbt to recognise.protofiles and include them in the packaged jar. Without this plugin there won't be any.protofile made available in the packaged jar.Make sure to add
organizationsettings in yourbuild.sbtto prepare jar correctly.Also, if you wish to cross-compile this jar to multiple versions add following entries in your
build.sbt:and then to publish:
With appropriate jars published you can now add them as dependencies in your client and server projects like so:
You can check out this project I am working on to see this in action.
Alternate Way
An alternate way I figured is that you can keep your
.protofiles in arootdirectory and then refer them in client and serverbuild.sbtlike so:Checkout this project to see it in action.