0

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

ringo
  • 3
  • 1
  • 1
    There are two options. One is to also include generated case class with your proto files and the other is to not include. Which one do you need? – Ivan Stanislavciuc Apr 05 '22 at 11:10
  • Good question. I was going to only include the .proto files, as the question specifies. This is because the shared library is cross compiled to scala and scalajs. However, I'm now thinking the better way to go is to generate the scala files and include them only in the scala version of the library. I'm very much feeling as I go on this one. – ringo Apr 05 '22 at 12:49

1 Answers1

1

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"
thesamet
  • 6,382
  • 2
  • 31
  • 42
  • Thanks! I did not realise this one line option existed. My situation was further complicated because the project is cross-compiled for scalajs. It took me a while to figure out that the `sourceDirectory` in this set up is actually `.jvm/src` and `.js/src`. I settled on compiling the `.proto` files to classes rather than sharing them and compiling in each app using the library. – ringo Apr 06 '22 at 10:48
  • 3
    I just realised you're the sbt-protoc project owner! Many thanks for a) your awesome open source software, and b) answering my question – ringo Apr 06 '22 at 11:47