Configure SBT

Add the sbt dependencies

ScalaPB is a compiler plugin that automatically generates Scala case classes for your messages and stubs for your services. Generating GRPC stubs for services is enabled by default. To use ScalaPB add the ScalaPB’s sbt plugin to your project.

First create a file named project/protoc.sbt containing the following line (already completed in sample project):

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

libraryDependencies += "com.trueaccord.scalapb" %% "compilerplugin" % "0.6.6"

Then add the following lines to your build.sbt (already completed in sample project):

libraryDependencies ++= Seq(
  "com.auth0" % "java-jwt" % "3.2.0",
  "io.grpc" % "grpc-netty" % grpcJavaVersion,
  "com.trueaccord.scalapb" %% "scalapb-runtime-grpc" % scalapbVersion  % "protobuf"
)

PB.targets in Compile := Seq(
  scalapb.gen() -> (sourceManaged in Compile).value
)

Default Behavoir

The plugin assumes your proto files are under src/main/protobuf, however this is configurable using the PB.protoSources in Compile setting. By default, sbt-protoc invokes protoc 3.0.0 that is shipped with protoc-jar.

The generated Scala source files are put in target/scala-2.12/src_managed

It then compiles these generated sources.

Running on Windows

Generating Scala code on Windows requires Python 2.x to be installed on your system. If Python is not installed on your system, you can download it from here.

If Python.exe can be found in your PATH, then ScalaPB should just work. If not, you can set the location of the Python executable explicitly:

PB.pythonExe := "C:\\Python27\\Python.exe"

Creating a service

When you run sbt compile, ScalaPB will generate code for your servers. This includes an asynchronous client, a blocking and asynchronous stub and a base trait you can extend to implement the server side.

Generate Stubs

Once you have the proto file and the SBT plugin configured, generate the Scala class files from sbt by running compile:

sbt compile

All Protobuffer 3 messages gRPC stubs should be generated under authservice/target/scala-2.12/src_managed

find . -name 'src_managed'