Frequently Asked Questions
IntelliJ complains on duplicate files (“class is already defined”)
If you are using sbt-protoc this should not happen. Please file a bug.
If you are still using sbt-scalapb, please switch to sbt-protoc as described in the installation instruction.
sbt-protobuf which sbt-scalapb relies on defaults to generating the case
target/src_managed/compiled_protobuf/. This leads to a situation
target/src_managed/compiled_protobuf/ and its parent,
are considered source directories and the source files are seen twice. To
eliminate this problem, let’s tell sbt-protobuf to generate the sources into
the parent directory. Add this to your
If you generate Java sources, add,
How do I use ScalaPB with Maven?
ScalaPB can be invoked in your Maven build by calling ScalaPBC, a standalone Java application that generates code. See an example project.
The relevant parts are marked with “Add the generated folder as a source” and “Compile the proto file(s)”.
I am getting “Import was not found or had errors”
If you are using sbt-protoc and importing protos like
or common protocol buffers like
Add the following to your
libraryDependencies += "com.trueaccord.scalapb" %% "scalapb-runtime" % com.trueaccord.scalapb.compiler.Version.scalapbVersion % "protobuf"
sbt-protoc to extract protos from this jar (and all its
dependencies, which includes Google’s common protos), and make them available
in the include path that is passed to protoc.
If you are not using sbt (for example, spbc), then you need to make those files available on the file system.
How do I generate Scala code for protos from another jar?
Include the jar as a
protobuf dependency in your libraryDependencies:
libraryDependencies += "com.somepackage" %% "that-has-jar" % "1.0" % "protobuf"
This will tell sbt-protoc to extract the protos from that jar into
target/scala-2.vv/protobuf-external. This makes it possible to
those protos from your local protos. sbt-protoc looks for protocol buffers to
compile in the directories listed in
PB.protoSources. There you need to
add a line like this to your
PB.protoSources in Compile += target.value / "protobuf_external"
You may find other protos under
protobuf_external that you do not wish to
compile. You can exclude them by adding an
includeFilter in PB.generate := new SimpleFileFilter( (f: File) => f.getParent.endsWith("com/thesamet/protos"))
See full example here.