我正在尝试使用scalapb从我的protobuf中生成case类。但是,我现在正在编译错误。
我的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)。我很好奇,应该使用哪一个,以及如何恰当地使用它?
非常感谢!
发布于 2019-01-09 04:09:31
ScalaPB的作者在这里。大约两年前,ScalaPB已经过渡到在TrueAccord之外开发,因此我们随后相应地更改了工件和包的名称。
您在问题中引用了在此转换之前发布的非常旧的版本(0.5.26)。我建议您按照documentation中的说明使用最新版本(0.8.x)。如果你遇到任何问题,请不要犹豫在这里或在我们的Gitter频道上询问。
发布于 2019-01-08 07:20:27
每个https://scalapb.github.io/migrating.html
从0.7.0版开始,ScalaPB工件以com.thesamet.scalapb组id发布,而不是以com.trueaccord.scalapb组id发布。
此外,com.trueaccord.scalapb中的所有类都被移动到scalapb顶级包中。在0.7.x中,我们将类型别名和引用保留在原始的com.trueaccord.scalapb位置,这样您可能会收到弃用警告,但您的代码不太可能崩溃。
此外,看起来作者希望您使用sbt-protoc插件。
然而,如果你发现有必要使用sbt-scalapb,我认为修复方法是在你的build.sbt中启用这个插件:
enablePlugin(ScalaPbPlugin)
The ScalaPbPlugin source显示它不是一个自动插件,因此需要手动启用。
https://stackoverflow.com/questions/54082861
复制相似问题