Installing ScalaPB

Installing in SBT (Recommended!)#

To automatically generate Scala case classes for your messages add ScalaPB's sbt plugin to your project. Create a file named project/scalapb.sbt containing the following lines:

addSbtPlugin("com.thesamet" % "sbt-protoc" % "1.0.6")
libraryDependencies += "com.thesamet.scalapb" %% "compilerplugin" % "0.11.11"

Add the following line to your build.sbt:

Compile / PB.targets := Seq(
scalapb.gen() -> (Compile / sourceManaged).value / "scalapb"
)
// (optional) If you need scalapb/scalapb.proto or anything from
// google/protobuf/*.proto
libraryDependencies ++= Seq(
"com.thesamet.scalapb" %% "scalapb-runtime" % scalapb.compiler.Version.scalapbVersion % "protobuf"
)

ScalaPB will look for protocol buffer (.proto) files under src/main/protobuf, which can be customized. Running the compile command in sbt will generate Scala sources for your protos and compile them.

For additional configuration options, see ScalaPB SBT Settings.

Running Standalone Using scalapbc#

If you would like to compile protocol buffers into Scala outside SBT, you can use scalapbc (ScalaPB compiler).

See ScalaPBC.

Running from Maven#

Using ScalaPBC, you can get maven to generate the code for you. Check out the ScalaPB Maven example.

Next:#

Read about the Generated Code.