5

我的 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
4

1 回答 1

0

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

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

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

你可以在这里找到这个插件的最新版本

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

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

addSbtPlugin("com.twitter" % "scrooge-sbt-plugin" % "18.4.0")
于 2018-04-15T01:49:40.603 回答