Beta
A Gradle plugin for protoc, the code generator behind Google's Protocol Buffers.
Most Gradle plugins out there don't seem to do a great job of external protoc plugins (e.g. my own rpckit). This particular Gradle plugin tries to make the interface to third party protoc language support & plugins just as easy as for built-in languages.
apply plugin: 'java'
apply plugin: 'protoc'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'co.tomlee.gradle.plugins:gradle-protoc-plugin:0.0.3'
}
}
repositories {
mavenCentral()
}
dependencies {
//
// Choose whatever version is appropriate here
//
compile 'com.google.protobuf:protobuf-java:2.5.0'
}
This will:
- Create a
compileProto
task and hook it up as a dependency ofcompileJava
- Configure
compileProto
to inspectsrc/main/proto
and write out Java code tosrc/main/gen-java
. - Add
src/main/gen-java
tosourceSets.main.java
- Create a
cleanProto
task and hook it up as a dependency ofclean
If you don't use apply plugin: "java"
, the compileProto
task will be created
but will not be configured to generate Java code by default.
This is only necessary if you want to use a protoc
binary that is not on
your PATH
:
protoc {
executable "/usr/bin/protoc"
}
protoc {
path "path/to/protofiles"
path "path/to/more/protofiles"
}
protoc version 2.3.0+ supports plugins, which is neat:
compileProto {
plugins {
//
// External protoc plugins are supported too
//
some_external_plugin {
//
// Optional if the plugin is on your $PATH and looks like `protoc-gen-<name>`
//
executable "/usr/local/bin/some-external-protoc-plugin"
out destinationDir
//
// Options will be passed through to the protoc plugin on the command line.
// Option values will be coerced to strings for the command line.
//
option foo: true
option bar: 123
option baz: "boz"
}
}
}
ext.destination = file("build/gen-proto")
sourceSets.main.java.srcDir destination.path
task myProtoCompile(type: ProtobufCompile) {
inputs.files fileTree("src/main/my-proto").include("**/*.proto")
plugins {
cpp {
out destination
}
python {
out destination
}
}
}
MIT
Please log defects and feature requests using the issue tracker on github.
gradle-protoc-plugin was written by Tom Lee.