0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ScalaのgRPCプロジェクトでもサードパーティのprotobufを使いたい

Last updated at Posted at 2020-09-16

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() がないと自動生成で重複クラスが出てきちゃうから付けとくのがオススメらしい。

おわり

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?