我有一个包含以下build.sbt
的scala grpc protobuf项目。
ThisBuild / version := "0.1.0-SNAPSHOT"
val openRtbCoreVersion = "1.5.5"
val googleCommonProtosVersion = "1.12.0"
val commonSettings: Seq[Def.Setting[_]] = Seq[Def.Setting[_]](
scalaVersion := "2.12.14",
organization := "com.td",
)
def scalaGrpcSettings: Seq[Def.Setting[_]] = Seq[Def.Setting[_]](
libraryDependencies += "com.thesamet.scalapb" %% "scalapb-runtime-grpc" % scalapb.compiler.Version.scalapbVersion,
libraryDependencies += "com.google.api.grpc" % "proto-google-common-protos" % googleCommonProtosVersion % "protobuf",
PB.targets in Compile := Seq(
PB.gens.java -> (sourceManaged in Compile).value,
scalapb.gen(javaConversions = true) -> (sourceManaged in Compile).value
),
PB.includePaths in Compile := Seq(
target.value / "protobuf_external",
),
PB.protoSources in Compile := Seq(
PB.externalIncludePath.value / "google" / "api",
target.value / "protobuf_external",
new File("definitions/common")
),
PB.additionalDependencies := Nil
)
lazy val root = (project in file("."))
.settings(
name := "proto-path-error"
).settings(scalaGrpcSettings)
project/plugins.sbt
文件是-
addSbtPlugin("com.thesamet" % "sbt-protoc" % "0.99.20")
libraryDependencies += "com.thesamet.scalapb" %% "compilerplugin" % "0.10.0"
project/build.properties
是-
sbt.version = 1.3.13
src/main/protobuf/definitions/common/common.proto
-
syntax = "proto2";
option java_outer_classname = "CommonUtils";
package com.td.protobuf;
message CMap {
map<int32, Assets> cs = 1;
}
message Assets {
repeated int32 assets = 1;
}
整个项目都在这里的github 上
这个项目运行良好。我想将project/plugins.sbt
中的sbt-protoc
插件更新到1.0.0。
在我将sbt协议版本升级到1.0.0之后,当我进行sbt clean compile
-时,我得到了以下错误
/home/rajkumar/Coding/scala/proto-path-error/definitions/common/common.proto: File does not reside within any path specified using --proto_path (or -I). You must specify a --proto_path which encompasses this file. Note that the proto_path must be an exact prefix of the .proto file names -- protoc is too dumb to figure out when two paths (e.g. absolute and relative) are equivalent (it's harder than you think). [error] java.lang.RuntimeException: protoc returned exit code: 1 [error] at scala.sys.package$.error(package.scala:30) [error] at sbtprotoc.ProtocPlugin$.compile(ProtocPlugin.scala:438) [error] at sbtprotoc.ProtocPlugin$.compileProto$1(ProtocPlugin.scala:537) [error] at sbtprotoc.ProtocPlugin$.$anonfun$sourceGeneratorTask$12(ProtocPlugin.scala:544) [error] at sbt.util.FileFunction$.$anonfun$cached$1(FileFunction.scala:73) [error] at sbt.util.FileFunction$.$anonfun$cached$4(FileFunction.scala:146) [error] at sbt.util.Difference.apply(Tracked.scala:323) [error] at sbt.util.Difference.apply(Tracked.scala:303) [error] at sbt.util.FileFunction$.$anonfun$cached$3(FileFunction.scala:142) [error] at sbt.util.Difference.apply(Tracked.scala:323) [error] at sbt.util.Difference.apply(Tracked.scala:298) [error] at sbt.util.FileFunction$.$anonfun$cached$2(FileFunction.scala:141) [error] at sbtprotoc.ProtocPlugin$.$anonfun$sourceGeneratorTask$4(ProtocPlugin.scala:549) [error] at scala.Function1.$anonfun$compose$1(Function1.scala:49) [error] at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:62) [error] at sbt.std.Transform$$anon$4.work(Transform.scala:67) [error] at sbt.Execute.$anonfun$submit$2(Execute.scala:281) [error] at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:19) [error] at sbt.Execute.work(Execute.scala:290) [error] at sbt.Execute.$anonfun$submit$1(Execute.scala:281) [error] at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:178) [error] at sbt.CompletionService$$anon$2.call(CompletionService.scala:37) [error] at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) [error] at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [error] at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) [error] at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [error] at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [error] at java.base/java.lang.Thread.run(Thread.java:829) [error] (Compile / protocGenerate) protoc returned exit code: 1 [error] Total time: 2 s, completed Sep 9, 2022, 7:15:30 PM
我在插件升级中错过了什么。知道我该如何解决这个错误吗?
build.sbt中有许多问题需要修复,以更新sbt协议1.0.x。也许它依赖于修复的旧行为。让我们首先从protoc报告的错误开始:
File does not reside within any path specified using --proto_path (or -I).
You must specify a --proto_path which encompasses this file. Note that the
proto_path must be an exact prefix of the .proto file names -- protoc is too
dumb to figure out when two paths (e.g. absolute and relative) are
equivalent (it's harder than you think).
换句话说,我们为其生成源的每个文件都需要在";proto_path";。ScalaPB会自动为您设置proto_path,除非您通过使用:=
手动重置它来规避它,如图所示:
PB.includePaths in Compile := Seq(
target.value / "protobuf_external",
),
由于默认情况下protobuf_external
在proto_path中(也在旧版本中(,因此这些行是不必要的,应该删除。
看来你想解开proto-google-common-protos
中的质子。有一个快捷方式:使用protobuf-src
而不是protobuf
作为作用域:
libraryDependencies += "com.google.api.grpc" % "proto-google-common-protos" % googleCommonProtosVersion % "protobuf-src",
总之,您的配置应该是:
def scalaGrpcSettings: Seq[Def.Setting[_]] = Seq[Def.Setting[_]](
libraryDependencies += "com.thesamet.scalapb" %% "scalapb-runtime-grpc" % scalapb.compiler.Version.scalapbVersion,
libraryDependencies += "com.google.api.grpc" % "proto-google-common-protos" % googleCommonProtosVersion % "protobuf-src",
PB.targets in Compile := Seq(
PB.gens.java -> (sourceManaged in Compile).value,
scalapb.gen(javaConversions = true) -> (sourceManaged in Compile).value
),
PB.protoSources in Compile ++= Seq(
new File("definitions/common")
)
)