Skip to content
Gradle plugin for Google Protocol Buffers
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
example Updating plugin dependency in example. Jul 26, 2015
gradle/wrapper Bumping version to 0.3.0. Also updating to gradle 1.12. May 16, 2014
.gitignore updated .gitignore to match default eclipse project setup Jul 20, 2015
LICENSE-2.0.txt Adding copy of Apache 2.0 license. Jun 15, 2013
build.gradle Releasing 0.5.0. Jul 26, 2015 Renaming sample file. Jan 24, 2014
gradlew.bat Promoting source code from initial development of plugin. Jun 15, 2013

Gradle Protobuf Plugin

  • Author: Andrew Kroh
  • Download: See maven central
  • License: Apache License, Version 2.0
  • Requirements: Java 1.5+
  • Google Protocol Buffer Compiler (protoc): Any version

What is it?

This is a plugin for Gradle that enables compiling Google Protocol Buffer .proto files into data access classes. It generates Java, CPP, and Python source files from the .proto files in src/main/proto.

This plugin adds a dependency on the Java plugin so that it can compile the generated Java source files.

This plugin generates a sources jar that contains all of the Java sources (including those generated from the .proto files) in this project.

The Protocol Buffer compiler must be on the path for the plugin to work. If the protocol buffer is in a different location then specify the full path to the compiler in your build.gradle file using protobuf.compiler = '/full/path/protoc'.


apply plugin: 'protobuf'

The plugin JAR needs to be defined in the classpath of your build script. It is available from maven central.

buildscript {
    repositories {

    dependencies {
        classpath 'com.andrewkroh.gradle:gradle-protobuf-plugin:0.5.0'

The plugin automatically adds a dependency on the google protobuf jars so all you need to do is specify what repository(s) to use.

repositories {

Project Layout

Simply put your .proto files in src/main/proto.


The protobuf plugin defines the following task:

  • compileProto - Generates source files by compiling .proto files.


The protobuf plugin adds a protobuf extension to the project which allows you to override the default configuration of the plugin.

  • version - Protocol Buffers version that your project requires. By specifying this value the plugin will verify that it is using specified version of the compiler.
  • src - Source directory for your .proto files. The value is relative to the project root.
  • compiler - Name (or full path) of the Google Protocol Buffer compiler that the plugin will execute.
  • outputCpp - Output directory for generated CPP source files. The value is relative to the project build directory.
  • outputJava - Output directory for generated java source files. The value is relative to the project build directory.
  • outputPython - Output directory for generated python source files. The value is relative to the project build directory.
  • outputToProjectDir - Output generated files relative to project root directory instead of relative to build directory. Defaults to false.
  • autoDependency - Activate or deactivate automatic dependency creation. If true, a compile time dependency on is added automatically based on the Protocol Buffers version number. Defaults to true.


See the example directory in this repository.

You can’t perform that action at this time.