Generate sources from IDL
While it is possible to use Mu by hand-writing your service definitions, message
classes and clients in Scala, we recommend you use
sbt-mu-srcgen to generate
this code from Protobuf/Avro/OpenAPI IDL files.
IDL files are language-agnostic, more concise than Scala code, easily shared with 3rd parties, and supported by a lot of existing tools.
Mu can generate code from a number of different IDL formats:
- message classes, gRPC server and client from Protobuf
.protofiles (see Generating sources from Protocol Buffers for detailed instructions)
- message classes, gRPC server and client from Avro
.avdlfiles (see Generating sources from Avro)
- message classes and REST client from OpenAPI
.yamlfiles (see the OpenAPI REST client tutorial)
Add the following line to project/plugins.sbt:
addSbtPlugin("io.higherkindness" % "sbt-mu-srcgen" % "0.26.0")
For users of the
v0.22.x and below, the plugin is enabled automatically as soon as it’s added to the
project/plugins.sbt. However, for users of the
v0.23.x and beyond, the plugin needs to be manually enabled for any module for which you want to generate code. To enable the module, add the following line to your
Once the plugin is installed and enabled, you can configure it
How to use the plugin
muSrcGen sbt task generates Scala source code from IDL files.
The plugin will automatically integrate the source generation into your compile
process, so the sources are generated before compilation when you run the
You can also run the sbt task manually:
```shell script sbt muSrcGen
## Import You will need to add this import at the top of your `build.sbt`: ```sbt import higherkindness.mu.rpc.srcgen.Model._
For an explanation of the plugin’s settings, see the source generation reference.