A scratch-built, modern Maven plugin for seamless protoc integration. Provides support for native and JVM-based protoc plugins, as well as automatic dependency resolution and incremental code generation.
Note
Full documentation with usage examples can be found within the plugin documentation, and examples are present in the integration tests.
Getting started is very simple. The following will compile any sources that are found in
src/main/protobuf
to Java classes and pop them in target/generated-sources
where Maven
will automatically discover them and compile them to Java bytecode.
<plugin>
<groupId>io.github.ascopes</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<configuration>
<protocVersion>${protobuf-java.version}</protocVersion>
</configuration>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
Tip
Any *.proto
files that are discovered in project dependencies will be made available
to protoc
,
so you can import them in exactly the same way you would with Java classes
Other language generation targets are also available. This plugin provides support for generating all the languages that protoc supports out of the box, including Kotlin, Python, Python typeshed stubs, Ruby, PHP, C#, C++, and Rust.
The following will generate Java classes and corresponding Kotlin wrappers:
<plugin>
<groupId>io.github.ascopes</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<configuration>
<kotlinEnabled>true</kotlinEnabled>
<protocVersion>${protobuf-java.version}</protocVersion>
</configuration>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
Native Maven dependency management is supported out of the box, allowing you to use Maven as an artifact registry for bundles of Proto files seamlessly.
<project>
...
<dependencies>
<dependency>
<groupId>org.example.protos</groupId>
<artifactId>user-protos</artifactId>
<version>1.2.3</version>
<type>zip</type>
</dependency>
</dependencies>
<plugins>
<plugin>
<groupId>io.github.ascopes</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<configuration>
<protocVersion>${protobuf-java.version}</protocVersion>
</configuration>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</project>
The following snippet will compile any protobuf sources in src/main/protobuf
to Java source code,
and then proceed to generate gRPC wrappers and Reactor gRPC wrappers.
<plugin>
<groupId>io.github.ascopes</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<configuration>
<protocVersion>${protobuf-java.version}</protocVersion>
<!-- Vanilla protoc plugins - these are platform specific executables
just like protoc is. -->
<binaryMavenPlugins>
<binaryMavenPlugin>
<groupId>io.grpc</groupId>
<artifactId>protoc-gen-grpc-java</artifactId>
<version>${grpc.version}</version>
</binaryMavenPlugin>
</binaryMavenPlugins>
<!-- JVM plugins are distributed as JARs rather than native system
executables. The protobuf-maven-plugin will automatically bootstrap
them for you. -->
<jvmMavenPlugins>
<jvmMavenPlugin>
<groupId>com.salesforce.servicelibs</groupId>
<artifactId>reactor-grpc</artifactId>
<version>${reactor-grpc.version}</version>
</jvmMavenPlugin>
</jvmMavenPlugins>
</configuration>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
- β - actively supported/available
- π - not supported, but open for discussion
- β - not supported, nor planned
Feature | Support |
---|---|
Maven 3.8 Support | β |
Maven 3.9 Support | β |
Maven 4.x Support | β |
Java 11 Support | β |
Java 17 Support | β |
Java 21 Support | β |
Java 24 Support | β |
Linux x86_64 | β |
Linux ARM64 | β |
macOS x86_64 | β |
macOS ARM64 | β |
Windows x86_64 | β |
Android Termux | β * |
Note
Maven integration is tested with the newest bugfix of each minor version that is listed (e.g. 3.9.9).
Tip
* Only supports using protoc
from the system $PATH
at this time.
Feature | Support |
---|---|
Java | β |
Kotlin | β (JVM shims out of the box, multiplatform via third-party protoc plugins) |
C# | β |
C++ | β |
Objective C | β |
PHP | β |
Ruby | β |
Rust | β |
Python and PYI stubs | β |
Other languages and frameworks | β (via third-party protoc plugins) |
Feature | Support |
---|---|
From Maven repositories | β (any Google-released version) |
From system path | β (as long as it is installed first) |
From a URL | β (no SOCKS/HTTP proxy support at this time) |
Feature | Support |
---|---|
Proto2 | β |
Proto3 | β |
Editions | β |
Failing on warnings | β (opt-in via plugin configuration) |
Lite builds | β (opt-in via plugin configuration) |
Generation of binary descriptors | β (opt-in via plugin configuration) |
Controlling import inclusion in binary descriptors | β (opt-in via plugin configuration) |
Controlling source info inclusion in binary descriptors | β (opt-in via plugin configuration) |
Building from FileDescriptorSet descriptors | β |
Feature | Support |
---|---|
Incremental compilation | β |
Attaching protobuf sources to generated JARs | β |
Attaching generated binary descriptors to builds | β |
Detecting importable dependencies from project <dependencies/> |
β |
Detecting importable dependencies from provided filesystem paths | β |
Respecting project <dependencyManagement/> |
β |
Compiling proto files from dependencies |
β (opt-in) |
Controlling binary descriptor type | β |
Controlling binary descriptor classifier | β |
Controlling binary descriptor attachment | β |
Generation of main sources | β |
Generation of test sources | β |
Controlling the dependencies that are resolved by Maven scope | β |
Marking generates sources as compilation candidates | β |
Creating protobuf ZIP archives* | π |
Creating protobuf TAR archives* | π |
Generating JAR-based protoc plugins** |
π |
Consuming TAR archives for imports and sources | π |
Tip
* This can currently be performed using maven-assembly-plugin
.
** Set the Main-Class
attribute in the MANIFEST.MF to do this. Use maven-shade-plugin
if you need a fat JAR
(not required for use with protobuf-maven-plugin
, but may be useful for other use
cases with third party tooling and build systems).
Feature | Support |
---|---|
Calling binary protoc plugins | β (from Maven repositories, URLs, system path) |
Calling JVM-based protoc plugins | β (from Maven repositories, URLs, system path -- generates the shims automatically for you) |
Calling plugins distributed in tarballs | π |
Feature | Support |
---|---|
Importing paths without adding to the Maven project | β (via plugin configuration) |
Generating code from additional paths without adding to the Maven project | β (via plugin configuration) |
Controlling includes and excludes by path | β (via Glob expressions in plugin configuration) |
Failing on invalid dependencies | β (opt-in via plugin configuration) |
Failing on missing sources | β (opt-out via plugin configuration) |
Controlling whether transitive dependencies are included | β (globally, or per dependency via plugin configuration) |