Skip to main content

Generate stubs for multiple languages

More information

Let's generate stubs for a few languages. Create the file buf.gen.yaml at the root of the repository:

version: v1beta1
- name: java
out: java
- name: cpp
out: cpp

Then, run:

$ buf generate -o gen

This will generate Java stubs to gen/java, and C++ stubs to gen/cpp.

Behind the scenes, this command:

  • Discovers all Protobuf files per your configuration.
  • Copies all Protobuf file content into memory.
  • Compiles all Protobuf files.
  • Splits the compiled result into chunks per directory, and invokes the java and cpp protoc built-in plugins per directory in parallel.
  • Combines the result, and writes to the given directories per the template.

Feel free to experiment with other plugins as well.

When you are done, run rm -rf gen to clean up your work.