Gradle Protoc Plugin

Gradle plugin for protoc, the code generator typically associated with Google's Protocol Buffers

License

License

Categories

Categories

Gradle Build Tools
GroupId

GroupId

co.tomlee.gradle.plugins
ArtifactId

ArtifactId

gradle-protoc-plugin
Last Version

Last Version

0.0.3
Release Date

Release Date

Type

Type

jar
Description

Description

Gradle Protoc Plugin
Gradle plugin for protoc, the code generator typically associated with Google's Protocol Buffers
Project URL

Project URL

http://github.com/thomaslee/gradle-protoc-plugin
Source Code Management

Source Code Management

http://github.com/thomaslee/gradle-protoc-plugin

Download gradle-protoc-plugin

How to add to project

<!-- https://jarcasting.com/artifacts/co.tomlee.gradle.plugins/gradle-protoc-plugin/ -->
<dependency>
    <groupId>co.tomlee.gradle.plugins</groupId>
    <artifactId>gradle-protoc-plugin</artifactId>
    <version>0.0.3</version>
</dependency>
// https://jarcasting.com/artifacts/co.tomlee.gradle.plugins/gradle-protoc-plugin/
implementation 'co.tomlee.gradle.plugins:gradle-protoc-plugin:0.0.3'
// https://jarcasting.com/artifacts/co.tomlee.gradle.plugins/gradle-protoc-plugin/
implementation ("co.tomlee.gradle.plugins:gradle-protoc-plugin:0.0.3")
'co.tomlee.gradle.plugins:gradle-protoc-plugin:jar:0.0.3'
<dependency org="co.tomlee.gradle.plugins" name="gradle-protoc-plugin" rev="0.0.3">
  <artifact name="gradle-protoc-plugin" type="jar" />
</dependency>
@Grapes(
@Grab(group='co.tomlee.gradle.plugins', module='gradle-protoc-plugin', version='0.0.3')
)
libraryDependencies += "co.tomlee.gradle.plugins" % "gradle-protoc-plugin" % "0.0.3"
[co.tomlee.gradle.plugins/gradle-protoc-plugin "0.0.3"]

Dependencies

compile (1)

Group / Artifact Type Version
org.codehaus.groovy : groovy-all jar 1.8.0

Project Modules

There are no modules declared in this project.

gradle-protoc-plugin

Status

Beta

Overview

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.

Usage

Minimal configuration

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 of compileJava
  • Configure compileProto to inspect src/main/proto and write out Java code to src/main/gen-java.
  • Add src/main/gen-java to sourceSets.main.java
  • Create a cleanProto task and hook it up as a dependency of clean

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.

If protoc is not on your PATH

This is only necessary if you want to use a protoc binary that is not on your PATH:

protoc {
    executable "/usr/bin/protoc"
}

Modifying the protoc include path

protoc {
    path "path/to/protofiles"
    path "path/to/more/protofiles"
}

Using protoc plugins

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"
        }
    }
}

Defining your own ProtobufCompile tasks

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
        }
    }
}

License

MIT

Support

Please log defects and feature requests using the issue tracker on github.

About

gradle-protoc-plugin was written by Tom Lee.

Follow me on Twitter or LinkedIn.

Versions

Version
0.0.3
0.0.2
0.0.1