我正在尝试scalapb
从我的 protobuf 生成案例类。但是,我目前正在编译错误。
我有我scalapb.sbt
的如下:
addSbtPlugin("com.trueaccord.scalapb" % "sbt-scalapb" % "0.5.26")
libraryDependencies ++= Seq(
"com.trueaccord.scalapb" %% "compilerplugin" % "0.5.26",
"com.github.os72" % "protoc-jar" % "3.0.0-b2.1"
)
而且,我build.sbt
的如下:
// for scalapb
import com.trueaccord.scalapb.{ScalaPbPlugin => PB}
PB.targets in Compile := Seq(
scalapb.gen() -> (sourceManaged in Compile).value
)
PB.protobufSettings
PB.runProtoc in PB.protobufConfig := (args =>
com.github.os72.protocjar.Protoc.runProtoc("-v241" +: args.toArray))
libraryDependencies ++= Seq(
"io.grpc" % "grpc-netty" % "0.14.0",
"com.trueaccord.scalapb" %% "scalapb-runtime-grpc" % (PB.scalapbVersion in PB.protobufConfig).value
)
另外,我创建了一个示例 .proto 文件src\main\protobuf
,如下所示:
syntax = "proto2"
package org.pk.stream.protos
message Tweet {
required string filter_level = 1;
}
现在,当我尝试时sbt compile
,我收到以下错误:
S:\MyRepos\LogStreaming>sbt compile
[info] Loading global plugins from C:\Users\pkumar25\.sbt\0.13\plugins
[info] Loading project definition from S:\MyRepos\RLoggerStreaming\project
S:\MyRepos\LogStreaming\build.sbt:21: error: object trueaccord is not a
member of package com
import com.trueaccord.scalapb.{ScalaPbPlugin => PB}
^
sbt.compiler.EvalException: Type error in expression
[error] sbt.compiler.EvalException: Type error in expression
[error] Use 'last' for the full log.
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? q
有人可以帮我解决这个错误吗?
我对这些scalapb
版本com.thesamet.scalapb
(https://scalapb.github.io/sbt-settings.html)和com.trueaccord.scalapb
(https://mvnrepository.com/artifact/com.trueaccord.scalapb)也有点困惑。我很好奇,应该使用哪一个以及如何恰当地使用它?
非常感激!