Home

Awesome

STATUS

Twitter is no longer maintaining this project or responding to issues or PRs. See https://github.com/twitter/scrooge/tree/master/scrooge-sbt-plugin as a replacment

sbt11-scrooge

Sbt11-scrooge is an sbt 0.11 plugin that adds support for using scrooge to perform thrift code generation.

How it works

The plugin registers itself as a source generator for the compile phase.

It fetches scrooge from the public Twitter maven repository, caches it in your project, and runs it against your thrift folder (usually src/main/thrift). The generated code folder (usually target/src_managed) is then added to your compile path.

Using it

See the sbt page on plugins for information on adding plugins. Usually, you need to add the following to your project/plugins.sbt file:

addSbtPlugin("com.twitter" % "sbt11-scrooge" % "1.0.0")

(But obviously, use the latest version number.)

If you use a build.sbt file, add this incantation:

import com.twitter.sbt._

seq(CompileThriftScrooge.newSettings: _*)

If you use Build.scala, add CompileThriftScrooge.newSettings to your settings list.

Here's a working example project/plugins.sbt:

resolvers += "twitter-repo" at "http://maven.twttr.com"

addSbtPlugin("com.twitter" %% "sbt11-scrooge" % "1.0.0")

addSbtPlugin("com.twitter" %% "sbt-package-dist" % "1.0.0")

And project/Build.scala:

import sbt._
import Keys._
import com.twitter.sbt._

object YourProject extends Build {
  val finagleVersion = "3.0.0"

  lazy val root = Project(
    id = "yourproject",
    base = file("."),
    settings = Project.defaultSettings ++
      StandardProject.newSettings ++
      CompileThriftScrooge.newSettings
  ).settings(
    name := "yourproject",
    organization := "com.example",
    version := "1.0.0-SNAPSHOT",
    scalaVersion := "2.9.1",
    
    libraryDependencies ++= Seq(
      "org.apache.thrift" % "libthrift" % "0.8.0" intransitive,
      "com.twitter" %% "finagle-core" % finagleVersion,
      "com.twitter" %% "finagle-thrift" % finagleVersion,
      "org.jboss.netty" % "netty" % "3.2.6.Final",
      "com.twitter" %% "scrooge-runtime" % "1.1.3"
    ),
    
    CompileThriftScrooge.scroogeVersion := "2.5.4",
    CompileThriftScrooge.scroogeBuildOptions := List("--finagle"),
    PackageDist.packageDistConfigFilesValidationRegex := Some(".*")
  )
}

Configuration

A full list of settings is in the (only) source file. Here are the ones you're most likely to want to edit:

Notes for helping work on sbt11-scrooge

Building

To build the plugin locally and publish it to your local filesystem:

$ sbt publish-local

Testing

There is a really crude scripted plugin. You can run it with:

$ sbt scripted

It currently has the version number hard-coded, so you may need to update that manually. (Note: On my mac, this just consumes all memory and dies. Does this work for anyone? -robey)

Notes for people upgrading from very old versions

Upgrading from sbt-thrift

The scala bindings are not 100% compatible with the scala bindings that were generated by sbt-thrift. Here are the notable differences:

Upgrading from java

If you're switching from java generated code, there are a few other (fairly large) differences: