1

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?

Jacek Laskowski
  • 72,696
  • 27
  • 242
  • 420
jedesah
  • 2,983
  • 2
  • 17
  • 29
  • This is the code in the sbt-plugin that supposedly fetches the thrift files from the artifact: https://github.com/twitter/scrooge/blob/b27e8dd100143202fc54b980bf2aa08d2050119f/scrooge-sbt-plugin/src/main/scala/com/twitter/ScroogeSBT.scala#L135 – jedesah Sep 24 '14 at 21:14
  • This would appear to be the code in the maven plugin that attaches these files to the packaged artifact. It would appear my hypothesis might be correct. https://github.com/twitter/scrooge/blob/0f6dc0f78ef124adca83c9cd65f700ba807806aa/scrooge-maven-plugin/src/main/java/com/twitter/MavenScroogeCompileMojo.java#L65 – jedesah Sep 24 '14 at 21:37

2 Answers2

2

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
}
reikje
  • 2,850
  • 2
  • 24
  • 44
  • Thx for the detailed answer! I made a PR against sbt-plugin to support this use case. Sorry, should have answered my own question, would have saved you some time. My change to sbt-plugin pretty much mirrors your own answer and also all the keys you defined are already defined by the Scrooge plugin. – jedesah Oct 03 '14 at 16:59
0

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

jedesah
  • 2,983
  • 2
  • 17
  • 29