scalasbtprotocol-buffersscalapb

How to share .proto (protobuf) files using a shared scala library using sbt


I have a few apps using shared .proto files. Each app's repo currently contains a copy of the files, which is not ideal and has recently created a problem when they accidentally diverged.

I would like to store the .proto files in a shared library which is already a common dependency for these apps. We're using sbt-protoc which has documentation for including .proto files from external libraries, but I can't find any information on how to package libraries that include them.

The .proto files are located in src/main/protobuf, but do not appear in the generated jar, which is presumably standard behaviour. I know you can tell sbt to include specific resource files, but I don't know if I've missed how to do it using sbt-protoc


Solution

  • To get protos included in the JAR, you can rely on standard sbt functionality, by adding a setting such as:

    Compile / unmanagedResourceDirectories += sourceDirectory.value / "protobuf"