Forked from intenthq/sbt-thrift-plugin@0a59b40.
A Thrift plugin for compiling Thrift sources into Java and adding the generated classes into the compile scope automagically.
In addition to Java, this plugin can also compile to the following languages:
- Javascript
- Ruby
- Python
- Delphi
These aren't supported as sources by SBT but will be available in a target/gen-<lang> directory for use by yourself in any suitable way you can think of.
By default, the plugin will compile to Java only. See the settings section below for details on how to enable other languages.
This is an SBT auto-plugin so all you have to do is add the following to your project/plugins.sbt:
addSbtPlugin("au.com.integradev.sbt" % "sbt-thrift-plugin" % "1.1.0")This plugin depends on having the thrift binary in your PATH — it does not add any speciifc dependency on libthrift for you. This means you should:
- Make sure the correct version of
thriftyou need is installed on your system and in yourPATH. - Make sure you add a dependency on the correct version of
libthriftto the application.
To set any settings, you'll need to import the settings into your build.sbt:
import au.com.integradev.sbt.ThriftPlugin._The following languages are supported by this plugin:
- Java
- Javascript (referred to in setting names as
Js) - Ruby
- Python
- Delphi
For all of these languages, the following SBT settings are available (where <lang> is the name of the language above):
thrift<lang>Enabled: Whether to enable generation of code for this language. Defaults totruefor Java,falsefor all other languages.thrift<lang>Options: Options to pass the Thrift compiler when generating the source files. Seethrift -helpfor the optional available for your chosen language. Defaults to an empty set of options for all languages.thrift<lang>OutputDir: The directory to save the generated files into. Defaults totarget/gen-<lang>.thriftGenerate<lang> / thriftPostProcessor: A transform function to post-process each generated file duringthriftGenerate<lang>after the main thrift generation command has finished.thriftGenerate<lang> / thriftCompileGeneratedSources: Whether to compile the files generated bythriftGenerate<lang>in this build'scompiletask.
All languages have a task, thriftGenerate<lang>, to generate the files manually. This task will automatically be run by SBT when running compile, as it is added as an SBT source generator.
The code for this plugin was adapted from intenthq/sbt-thrift-plugin@0a59b40 which in turn was adapted from the following source.