无法编译scrooge thrift插件生成的源代码

时间:2017-08-07 03:34:06

标签: scala thrift-protocol scrooge

我的plugins.sbt是

addSbtPlugin("com.twitter" % "scrooge-sbt-plugin" % "4.8.0")

我的build.sbt是

val finagleVersion = "6.45.0"

lazy val myProject = Project("FinagleTest", file("."))
   .settings(
   name := "FinagleTest",
   version := "1.0",
   scalaVersion := "2.12.2",
   libraryDependencies ++= Seq(
      "org.apache.thrift" % "libthrift" % "0.9.2",
      "com.twitter" %% "scrooge-core" % "4.18.0" exclude("com.twitter", "libthrift"),
      "com.twitter" %% "finagle-thrift" % finagleVersion exclude("com.twitter", "libthrift"),
      "com.twitter" %% "finagle-http" % finagleVersion,
      "com.twitter" %% "finagle-core" % finagleVersion
   ),
   scroogeThriftSourceFolder in Compile := {
      val base = baseDirectory.value
      base / "src/main/thrift"
   }
)

src/main/thrift文件夹

中创建了temprature_service.thrift文件
namespace * com.foo.temprature.thrift
struct TempratureDatum {
    1: i32 celcius,
    2: i64 timestamp
}

service TempratureService {
    void add(1: TempratureDatum datum);
    double mean();
}

并使用sbt clean scrooge-gen compile

进行编译

但是我收到了编译错误

[info] Compiling 5 Scala sources to /Users/Foo/IdeaProjects/FinagleTest/target/scala-2.12/classes...
[error] /Users/Foo/IdeaProjects/FinagleTest/target/scala-2.12/src_managed/main/com/foo/temprature/thrift/TempratureDatum.scala:481: value _equals is not a member of object scala.runtime.ScalaRunTime
[error]       _root_.scala.runtime.ScalaRunTime._equals(this, other) &&
[error]                                         ^
[error] /Users/Foo/IdeaProjects/FinagleTest/target/scala-2.12/src_managed/main/com/foo/temprature/thrift/TempratureService.scala:65: type mismatch;
[error]  found   : com.twitter.finagle.Service[com.foo.temprature.thrift.TempratureService.Add.Args,com.foo.temprature.thrift.TempratureService.Add.SuccessType]
[error]     (which expands to)  com.twitter.finagle.Service[com.foo.temprature.thrift.TempratureService.Add.Args,Unit]
[error]  required: com.twitter.finagle.Service[com.foo.temprature.thrift.TempratureService.Add.Args,com.foo.temprature.thrift.TempratureService.Add.Result]
[error]           add = ThriftServiceIface(self.Add, binaryService, pf, stats),
[error]                                   ^
[error] /Users/Foo/IdeaProjects/FinagleTest/target/scala-2.12/src_managed/main/com/foo/temprature/thrift/TempratureService.scala:66: type mismatch;
[error]  found   : com.twitter.finagle.Service[com.foo.temprature.thrift.TempratureService.Mean.Args,com.foo.temprature.thrift.TempratureService.Mean.SuccessType]
[error]     (which expands to)  com.twitter.finagle.Service[com.foo.temprature.thrift.TempratureService.Mean.Args,Double]
[error]  required: com.twitter.finagle.Service[com.foo.temprature.thrift.TempratureService.Mean.Args,com.foo.temprature.thrift.TempratureService.Mean.Result]
[error]           mean = ThriftServiceIface(self.Mean, binaryService, pf, stats)
[error]                                    ^
[error] /Users/Foo/IdeaProjects/FinagleTest/target/scala-2.12/src_managed/main/com/foo/temprature/thrift/TempratureService.scala:248: value _equals is not a member of object scala.runtime.ScalaRunTime
[error]           _root_.scala.runtime.ScalaRunTime._equals(this, other) &&
[error]                                             ^
[error] /Users/Foo/IdeaProjects/FinagleTest/target/scala-2.12/src_managed/main/com/foo/temprature/thrift/TempratureService.scala:373: value _equals is not a member of object scala.runtime.ScalaRunTime
[error]           _root_.scala.runtime.ScalaRunTime._equals(this, other) &&
[error]                                             ^
[error] /Users/Foo/IdeaProjects/FinagleTest/target/scala-2.12/src_managed/main/com/foo/temprature/thrift/TempratureService.scala:524: value _equals is not a member of object scala.runtime.ScalaRunTime
[error]           _root_.scala.runtime.ScalaRunTime._equals(this, other) &&
[error]                                             ^
[error] /Users/Foo/IdeaProjects/FinagleTest/target/scala-2.12/src_managed/main/com/foo/temprature/thrift/TempratureService.scala:705: value _equals is not a member of object scala.runtime.ScalaRunTime
[error]           _root_.scala.runtime.ScalaRunTime._equals(this, other) &&
[error]                                             ^
[error] 7 errors found

1 个答案:

答案 0 :(得分:0)

今天很有趣我正在写另一个节俭服务,我发现这个问题是我1年前发布的:)

幸运的是,解决方案非常简单。

上面代码中使用的插件版本非常陈旧。

您可以在此处找到此插件的最新版本

https://bintray.com/twittercsl/sbt-plugins/scrooge-sbt-plugin

如果我将plugins.sbt文件更新为

,问题就解决了
addSbtPlugin("com.twitter" % "scrooge-sbt-plugin" % "18.4.0")