ScalaPB

This module allows ScalaPB to be used in Mill builds. ScalaPB is a Protocol Buffers compiler plugin that generates Scala case classes, encoders and decoders for protobuf messages.

To declare a module that uses ScalaPB you can extend the mill.contrib.scalapblib.ScalaPBModule trait when defining your module.

This creates a Scala module which compiles .proto files in the protobuf folder of the module with ScalaPB and adds the resulting .scala sources to your module’s generatedSources.

build.sc
import $ivy.`com.lihaoyi::mill-contrib-scalapblib:`
import contrib.scalapblib._

object example extends ScalaPBModule {
  def scalaVersion = "2.12.6"
  def scalaPBVersion = "0.7.4"
}

This defines a project with the following layout:

build.sc
example/
    src/
    protobuf/
    resources/

Configuration options

  • scalaPBVersion (mandatory) - The ScalaPB version String e.g. "0.7.4"

  • scalaPBFlatPackage - A Boolean option which determines whether the .proto file name should be appended as the final segment of the package name in the generated sources.

  • scalaPBJavaConversions - A Boolean option which determines whether methods for converting between the generated Scala classes and the Protocol Buffers Java API classes should be generated.

  • scalaPBGrpc - A Boolean option which determines whether grpc stubs should be generated.

  • scalaPBSingleLineToProtoString - A Boolean option which determines whether the generated .toString methods should use a single line format.

  • scalaPBProtocPath - A Option[Path] option which determines the protoc compiler to use. If None, a java embedded protoc will be used, if set to Some path, the given binary is used.

  • scalaPBSearchDeps - A Boolean option which determines whether to search for .proto files in dependencies and add them to scalaPBIncludePath. Defaults to false.

  • scalaPBIncludePath - Additional paths to include .proto files when compiling.

If you’d like to configure the options that are passed to the ScalaPB compiler directly, you can override the scalaPBOptions task, for example:

build.sc
import $ivy.`com.lihaoyi::mill-contrib-scalapblib:`
import contrib.scalapblib._

object example extends ScalaPBModule {
  def scalaVersion = "2.12.6"
  def scalaPBVersion = "0.7.4"
  override def scalaPBOptions = "flat_package,java_conversions"
}

If you’d like to pass additional arguments to the ScalaPB compiler directly, you can override the scalaPBAdditionalArgs task, for example:

build.sc
import $ivy.`com.lihaoyi::mill-contrib-scalapblib:$MILL_VERSION`
import contrib.scalapblib._

object example extends ScalaPBModule {
  def scalaVersion = "2.12.6"
  def scalaPBVersion = "0.7.4"
  override def scalaPBAdditionalArgs =
    Seq(s"--zio_out=${T.dest.toIO.getCanonicalPath}")
}