The protos you are trying to generate code may depend on other protos which are currently are not a part of your build. We need to solve two problems:
- Making those proto files available to
protoc's import search path so the
importstatements in your protos don't cause errors and code is generated.
- Providing Scala classes for those third-party protos.
There are multiple ways to solve those problems.
Check whether a ScalaPB Common Protos package is already available for the protos. If the proto library you are looking for is unavailable, consider making a PR or filing a feature request.
You will add such libraries to your project twice: once with a
protobuf suffix and once without:
The first one makes
sbt-protoc unpack the protos from the jar and add them to the import search path so protoc can import them (Problem 1 above), and the second import adds the compiled Scala classes to your classpath (Problem 2 above). In this solution, protoc will not generate code for the third-party protos: the provided package already gives you compiled classes for the generated code.
Consider adding it to Common Protos. If this is not possible (for example, maybe the package is on a repository internal to your company), then you can have your SBT project download the library and build it by using the
protobuf-src config. For example:
This would make sbt-protoc download this JAR unpack it to
target/protobuf_external_src, and make it both available for imports and generate code for it (which solves both problems above at once).
intransitive() modifier, sbt-protoc would generate code for all the dependencies of this package, and this is generally undesirable - since this is likely to lead to duplicate classes being generated.
If the given package has dependencies, you will need to manually add them. The dependencies should be added with
protobuf-src scope if you want to build them too. If you already have compiled packages for these dependencies, add the package both with
protobuf and without like in the "common protos" example above.
It is recommended to create a separate SBT sub-project for the third-party protos. For example:
See full example here.