在 Scala 2.13.12 上编译生成的 zio-grpc 类时出现无效的包名称错误

问题描述 投票:0回答:1

我正在 scala 2.13.12 上创建 ZIO gRPC 客户端服务。

我从 .proto 生成了类并尝试编译我的项目并收到此错误:

[error] C:\Users\arsen\IdeaProjects\voicekit-grpc\target\scala-2.13\src_managed\main\scalapb\tinkoff\cloud\stt\v1\SpeechToText\SpeechToTextProto.scala:10:20: object annotations is not a member of package com.google.api
[error]     com.google.api.annotations.AnnotationsProto,
[error]                    ^
[error] C:\Users\arsen\IdeaProjects\voicekit-grpc\target\scala-2.13\src_managed\main\scalapb\tinkoff\cloud\stt\v1\SpeechToText\SpeechToTextProto.scala:129:22: object annotations is not a member of package com.google.api
[error]       com.google.api.annotations.AnnotationsProto.javaDescriptor,
[error]                      ^
[error] two errors found

我想在我的应用程序中使用来自 API 的 .proto 文件:

syntax = "proto3";

package tinkoff.cloud.stt.v1;
option go_package = "github.com/Tinkoff/voicekit-examples/golang/pkg/tinkoff/cloud/stt/v1";
option objc_class_prefix = 'TVKSR';

import "google/protobuf/duration.proto";
import "google/api/annotations.proto";

service SpeechToText { // Speech recognition.
  rpc Recognize(RecognizeRequest) returns (RecognizeResponse) { // Method to recognize whole audio at once: sending complete audio, getting complete recognition result.
    option (google.api.http) = {
      post: "/v1/stt:recognize"
      body: "*"
    };
  }
  rpc StreamingRecognize(stream StreamingRecognizeRequest)
    returns (stream StreamingRecognizeResponse); // Method for streaming recognition.

  rpc StreamingUnaryRecognize(stream StreamingUnaryRecognizeRequest) returns (RecognizeResponse) { // Method to synchronous recognize audio stream. Returns recognition result after all audio has been sent and processed.
    option (google.api.http) = {
      post: "/v1/stt:streaming_unary_recognize";
      body: "*";
    };
  }
}
......

这是我的build.sbt:

import scala.tools.nsc.io.JFile

lazy val root = project
  .in(file("."))
  .settings(
    name := "voicekit-grpc",
    version := "0.1.0-SNAPSHOT",

    scalaVersion := "2.13.12",
    Compile / PB.targets := Seq(
      scalapb.gen(grpc = true) -> (Compile / sourceManaged).value / "scalapb",
      scalapb.zio_grpc.ZioCodeGenerator -> (Compile / sourceManaged).value / "scalapb"
    ),
    Compile / PB.includePaths ++= Seq(new JFile("third_party/googleapis/")),
    libraryDependencies ++= Seq(
      "io.grpc" % "grpc-netty" % "1.50.1",
      "com.thesamet.scalapb" %% "scalapb-runtime-grpc" % scalapb.compiler.Version.scalapbVersion,
      "com.typesafe" % "config" % "1.4.3",
      "dev.zio" %% "zio-http" % "0.0.5",
      "com.fasterxml.jackson.core" % "jackson-databind" % "2.16.1",
      "com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.16.1",
      "com.thesamet.scalapb" %% "scalapb-runtime" % scalapb.compiler.Version.scalapbVersion % "protobuf"
    )
  )

这是我的plugins.sbt:

addSbtPlugin("com.thesamet" % "sbt-protoc" % "1.0.6")

libraryDependencies ++= Seq(
  "com.thesamet.scalapb.zio-grpc" %% "zio-grpc-codegen" % "0.6.1")

我搜索并手动下载外部原型依赖项到目录 /third_party

我尝试将外部依赖项的多个路径添加到 PB.includePaths,但没有帮助

scala grpc zio scalapb
1个回答
0
投票

尝试将依赖项添加到

build.sbt

"com.google.api.grpc" % "googleapis-common-protos" % "0.0.3" % "protobuf"

请注意

% "protobuf"
范围。

https://discuss.lightbend.com/t/use-googles-annotations-proto/3302

© www.soinside.com 2019 - 2024. All rights reserved.