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.scimport $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
Stringe.g."0.7.4" -
scalaPBFlatPackage - A
Booleanoption which determines whether the.protofile name should be appended as the final segment of the package name in the generated sources. -
scalaPBJavaConversions - A
Booleanoption which determines whether methods for converting between the generated Scala classes and the Protocol Buffers Java API classes should be generated. -
scalaPBGrpc - A
Booleanoption which determines whether grpc stubs should be generated. -
scalaPBSingleLineToProtoString - A
Booleanoption which determines whether the generated.toStringmethods should use a single line format. -
scalaPBProtocPath - A
Option[Path]option which determines the protoc compiler to use. IfNone, a java embedded protoc will be used, if set toSomepath, the given binary is used. -
scalaPBSearchDeps - A
Booleanoption which determines whether to search for.protofiles in dependencies and add them toscalaPBIncludePath. Defaults tofalse. -
scalaPBIncludePath - Additional paths to include
.protofiles 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.scimport $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.scimport $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}")
}