Scrooge SBT 插件不参与工件发布。你可以自己处理这个。在包含要发布的 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 publish
通过或将工件发布到存储库sbt 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
}