jedesah
jedesah

Reputation: 3033

How does publishing a "thrift repo" work with Scrooge and associated plugins?

Scrooge has both plugins for sbt and for maven. I am not really interested in the maven plugin.

It would appear the sbt plugin has the ability to extract thrift files from a dependency artifact. See the scroogeThriftDependencies option here

However I am left very perplexed as to how this works, because I have added the sbt-plugin to a repo with only thrift files. I sort of expected the plugin to publish an artifact somehow containing both the classes compiled from the generated code and the thrift sources itself so that a library depending on it and defining it's own thrift could access the thrift in order to compile it's own thrift.

I investigated the artifacts produced by my build and found absolutely no trace of thrift files.

Anyone have an idea how this might work? Does the maven plugin publish the thrift sources but this functionality was only added to sbt on the consuming side? Have I misunderstood something else?

Upvotes: 1

Views: 649

Answers (2)

jedesah
jedesah

Reputation: 3033

So this feature was never implemented in the sbt-plugin of Scrooge even if it was implemented for the maven plugin.

I issued a PR to fix this: https://github.com/twitter/scrooge/pull/153

Upvotes: 0

reikje
reikje

Reputation: 3064

The Scrooge SBT plugin is not involved in artifact publishing. You can take care of this yourself. In the project that contains the Thrift IDL files that you want to publish, add this to 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"
)

Publish the artifact to a repo via sbt publish or sbt publishLocal. Then in another project your build.sbt may look like this:

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"
)

which will include dependent Thrift IDL when you execute the scroogeGen task. So you may have a .thrift file like this and it will all work:

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
}

Upvotes: 2

Related Questions