【问题标题】:How does publishing a "thrift repo" work with Scrooge and associated plugins?发布“thrift repo”如何与 Scrooge 和相关插件一起使用?
【发布时间】:2014-11-19 12:25:40
【问题描述】:

Scrooge 有 sbt 和 maven 的插件。我对 maven 插件不是很感兴趣。

看起来 sbt 插件能够从依赖项工件中提取 thrift 文件。请参阅 scroogeThriftDependencies 选项here

但是,我对它的工作原理感到非常困惑,因为我已将 sbt-plugin 添加到只有 thrift 文件的 repo 中。我有点期望插件以某种方式发布一个工件,其中包含从生成的代码编译的类和节俭源本身,以便依赖于它并定义它自己的节俭的库可以访问节俭以编译它自己的节俭。

我调查了我的构建产生的工件,发现绝对没有任何 thrift 文件的痕迹。

有人知道这可能是如何工作的吗? maven 插件是否发布了节俭的资源,但这个功能只添加到消费端的 sbt 中?我是否误解了其他内容?

【问题讨论】:

标签: scala sbt sbt-plugin scrooge


【解决方案1】:

Scrooge SBT plugin 不参与工件发布。你可以自己处理这个。在包含您要发布的 Thrift IDL 文件的项目中,将其添加到 build.sbt

organization := "me"

name := "thrift-inherit-shared"

version := "0.1-SNAPSHOT"

scalaVersion := "2.10.4"

com.twitter.scrooge.ScroogeSBT.newSettings

lazy val thriftDirectory = settingKey[File]("The folder containing the thrift IDL files.")

thriftDirectory := {
  baseDirectory.value / "src" / "main" / "thrift"
}

lazy val thriftIDLFiles = settingKey[Seq[File]]("The thrift IDL files.")

thriftIDLFiles := {
  (thriftDirectory.value ** "*.thrift").get
}

// this makes sure the jar file will only contain the .thrift files and no generated classes
mappings in (Compile, packageBin) := {
  thriftIDLFiles.value map { thriftFile => (thriftFile, thriftFile.name)}
}

libraryDependencies ++= Seq(
  "org.apache.thrift" % "libthrift" % "0.9.1",
  "com.twitter" %% "scrooge-core" % "3.16.3"
)

通过sbt publishsbt publishLocal 将工件发布到存储库。然后在另一个项目中,您的 build.sbt 可能如下所示:

organization := "me"

name := "thrift-inherit-server"

version := "0.1-SNAPSHOT"

scalaVersion := "2.10.4"

com.twitter.scrooge.ScroogeSBT.newSettings

scroogeThriftDependencies in Compile := Seq("thrift-inherit-shared_2.10")

libraryDependencies ++= Seq(
  "me" %% "thrift-inherit-shared" % "0.1-SNAPSHOT",
  "org.apache.thrift" % "libthrift" % "0.9.1",
  "com.twitter" %% "scrooge-core" % "3.16.3"
)

当您执行scroogeGen 任务时,它将包括依赖的 Thrift IDL。所以你可能有一个这样的 .thrift 文件,它会工作的:

include "shared.thrift" <--- dependent IDL file

namespace java me.server.generated.thrift

struct UserEnvironment {
    1: shared.Environment env <--- defined in dependent IDL file
    2: i64 userId
}

【讨论】:

  • 感谢详细解答!我针对 sbt-plugin 做了一个 PR 来支持这个用例。对不起,应该回答我自己的问题,会节省你一些时间。我对 sbt-plugin 的更改几乎反映了您自己的答案,而且您定义的所有键都已由 Scrooge 插件定义。
【解决方案2】:

所以这个功能从未在 Scrooge 的 sbt-plugin 中实现,即使它是为 maven 插件实现的。

我发布了一个 PR 来解决这个问题:https://github.com/twitter/scrooge/pull/153

【讨论】:

    猜你喜欢
    • 2015-09-02
    • 1970-01-01
    • 2018-01-14
    • 2013-10-21
    • 2020-09-20
    • 2013-06-24
    • 1970-01-01
    • 2012-10-04
    • 2015-07-14
    相关资源
    最近更新 更多