googleapisとか公開されているprotobufをScalaプロジェクトで使う方法がわからなかったのでgitterで聞いた。
You may find this page helpful: https://scalapb.github.io/docs/third-party-protos/
You could either change the dependencies of proto-google-common-protos into protobuf-src dependency or use the common protos package provided by ScalaPB.
Also https://scalapb.github.io/docs/common-protos
結論、方法が2つあるみたい。
https://scalapb.github.io/docs/third-party-protos
その1: ScalaPB Common Protos を使う
よく使いそうなprotobufをまとめてくれてるので運が良ければそれが使えるかもしれない(大抵はこれでなんとかなりそう)。https://github.com/scalapb/common-protos
libraryDependencies ++= Seq(
"com.thesamet.scalapb.common-protos" %% "proto-google-common-protos-scalapb_0.10" % "1.17.0-0" % "protobuf",
"com.thesamet.scalapb.common-protos" %% "proto-google-common-protos-scalapb_0.10" % "1.17.0-0"
)
サフィックスのprotobuf
を付けるとjarを展開して自分らのprotobufのimportパスに追加してくれる。サフィックス無しの宣言は自動生成したコードをクラスパスに追加するのに必要。
その2: Mavenのライブラリを直接使う
例えば、googleapisのprotobufを使いたいときはこう。
libraryDependencies += "com.google.api.grpc" % "proto-google-common-protos" % version % "protobuf-src" intransitive ()
こっちの場合は protobuf-src
っていうのを宣言すると自分らのprotobufへの依存を解決できる。intransitive()
がないと自動生成で重複クラスが出てきちゃうから付けとくのがオススメらしい。