Generate Code from Thrift Definitions


You've created Thrift definitions (structs, services, etc.) and you need to generate either Thrift-based

  • classes for use within your Scala or Java project, or
  • libraries that can be used by your project or other projects.


Use the gen goal to generate code from Thrift definitions. Here's an example:

$ ./pants gen src/thrift/example:thrift-scala

If you need to compile a Scala or Java library target instead, use the compile goal instead.


There are two types of Thrift target definitions that you will find in BUILD files in existing projects:

  • java_thrift_library (for Scala and Java)
  • python_thrift_library (for Python)

You can use the gen and compile goals directly with java_thrift_library targets. Thus, you could target a BUILD file containing this definition...

  # Other parameters
) this using Pants:

$ ./pants gen src/thrift/example:thrift-java

To learn more about Thrift, check out the Thrift Example docs.

See Also

Generated by publish_docs from dist/markdown/html/src/docs/common_tasks/thrift_gen.html 2020-06-02T20:32:05.280324