Search code examples
sbtprotocol-buffersgrpc

SBT protobuf grpc configuration


I'm new to SBT, and i'm trying to convert gradle protobuf/grpc configuration to SBT.

I wonder if the Scala community had done this before me?

I've tried this plugin https://github.com/sbt/sbt-protobuf, but it does not provide any configuration to enable grpc compilation...


Solution

  • I actually faced a couple of problems myself trying to migrate from Gradle to SBT.

    Like you said, sbt-protobuf plugin doesn't have any grpc specific settings, yet it's possible, here are couple of settings you should double check:

    • Set the path and version of your protoc:

      version in PB.protobufConfig := "3.0.0" protoc in PB.protobufConfig := PATH_PROTOC

    • If needed set the location of your .proto files (default is src/main/protobuf):

      sourceDirectory in PB.protobufConfig := baseDirectory.value / "src" / "main" / "proto"

    • Finally, like Eric Anderson said, set extra options of protoc used by grpc-java. First options sets the path for your protoc-gen-grpc-java plugin bin; and second sets the output path of grpc-java to the same as sbt-protobuf:

      protocOptions in PB.protobufConfig ++= Seq( "--plugin=protoc-gen-grpc-java=" + PATH_GRPC_JAVA_PLUGIN, "--grpc-java_out=" + baseDirectory.value + "/target/src_managed/main/compiled_protobuf")

    I ended up putting a repository with all of this sorted out. Here it is, hope it helps!