Maven Protocol Buffers Plugin

Maven Protocol Buffers Plugin uses Protocol Buffer Compiler (protoc) tool to generate Java source files from .proto (protocol buffer definition) files for the specified project. For more information about the Protocol Buffer Compiler, please refer to Reference Guide.

The Plugin automatically scans all project dependencies for bundled .proto files, and configures proto_path of the Protocol Buffer Compiler to use those files as imports.

The Plugin automatically attaches the source .proto files to the resources of the project, so that they are later packaged into the final artifact and can be referenced as imports from the dependent projects or modules.

Goals Overview

Maven Protocol Buffers Plugin has the following goals:

  • protobuf:compile compiles main .proto definitions into Java files and attaches the generated Java sources to the project.
  • protobuf:test-compile compiles test .proto definitions into Java files and attaches the generated Java test sources to the project.
  • protobuf:compile-cpp compiles main .proto definitions into C++ files and attaches the generated C++ sources to the project.
  • protobuf:test-compile-cpp compiles test .proto definitions into C++ files and attaches the generated C++ test sources to the project.
  • protobuf:compile-python compiles main .proto definitions into Python files and attaches the generated Python sources to the project.
  • protobuf:test-compile-python compiles test .proto definitions into Python files and attaches the generated Python test sources to the project.
  • protobuf:compile-javanano uses JavaNano generator (requires protobuf compiler version 3 or above) to compile main .proto definitions into Java files and attaches the generated Java sources to the project.
  • protobuf:test-compile-javanano uses JavaNano generator (requires protobuf compiler version 3 or above) to compile test .proto definitions into Java files and attaches the generated Java test sources to the project.
  • protobuf:compile-custom compiles main .proto definitions using a custom protoc plugin.
  • protobuf:test-compile-custom compiles test .proto definitions using a custom protoc plugin.

Usage

General instructions on how to use Maven Protocol Buffers Plugin can be found on the usage page. Some more specific use cases are described in the examples given below.

In case you still have questions regarding the Plugin's usage, please have a look at the FAQ.

If you feel like the plugin is missing a feature or has a defect, you can fill a feature request or bug report in our issue tracker. When creating a new issue, please provide a comprehensive description of your concern. Especially for fixing bugs it is crucial that the developers can reproduce your problem. For this reason, entire debug logs, POMs or most preferably little demo projects attached to the issue are very much appreciated.

Of course, patches and pull requests are welcome, too. Contributors can check out the project from the source repository and will find supplementary information in the contributor's guide.

Examples

To provide you with better understanding of some usages of Maven Protocol Buffers Plugin, you can take a look into the following examples: