Gradle plugin for Google Protocol Buffers

Overview

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'.

Usage

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 {
        mavenCentral()
    }

    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 {
    mavenCentral()
}

Project Layout

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

Tasks

The protobuf plugin defines the following task:

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

Extensions

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 com.google.protobuf:protobuf-java is added automatically based on the Protocol Buffers version number. Defaults to true.

Example

See the example directory in this repository.

Comments
  • outputDir doesn't work

    outputDir doesn't work

    When using Intellij, I can't use the build directory as an include directory, so my files can't import the generated protos. What I really want is to generate the Proto.java files and have them automatically copied into my src tree.

    Setting outputJava doesn't seem to do anything. I am doing it like this:

    protobuf { outputJava = '$sourceDir' }

    But it still outputs the generated files to build/generated/java.

    bug 
    opened by kgreenek 3
  • new feature: deactivate/activate automatic dependency creation using ...

    new feature: deactivate/activate automatic dependency creation using ...

    ... a property switch.

    Reason: for testing the google protocol buffers 3.0.0 alpha the automatic dependency creation feature fails as the protoc version differs from the name of the runtime library. In order to allow the manual creation of the proper dependency, it was necessary for me to be able to deactivate the automatic creation.

    Maybe this is useful for someone else as well ...

    All the best, l00tr

    enhancement 
    opened by AntiTiming 2
  • Fixed issue with default project properties overwriting custom project p...

    Fixed issue with default project properties overwriting custom project p...

    ...roperties.

    Resolved issue with default project properties overwriting custom project properties by moving addCompileProtoTask and addSourceJarTask calls into project.afterEvaluate.

    Bumped version number to 0.3.1.

    Added project property for outputting generated files relative to build directory or relative to project root directory.

    opened by trulsmag 2
  • src option does not work

    src option does not work

    Hello,

    I can not get the src option working. The documentation states: " Source directory for your .proto files. The value is relative to the project root."

    however the plugin looks into src/main.

    My build.gradle file includes the following

    protobuf { version = '2.5.0' src = 'proto'
    }

    bug 
    opened by massiccio 2
  • Cannot run program

    Cannot run program "protoc"

    Caused by: java.io.IOException: Cannot run program "protoc": CreateProcess error=2, The system cannot find the file specified at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048) at java.lang.Runtime.exec(Runtime.java:620) at java.lang.Runtime.exec(Runtime.java:450)

    opened by dtracers 1
  • Fixed issue with custom project properties not taking effect.

    Fixed issue with custom project properties not taking effect.

    Resolved issue with not being able to set custom project properties by moving addCompileProtoTask and addSourceJarTask calls into project.afterEvaluate.

    Added a new project property "outputToProjectDir" for outputting generated files relative to project root directory instead of relative to build directory.

    Bumped version number to 0.4.0 since it is a patch for a bug and adds a new configuration option.

    opened by trulsmag 1
  • Usage example typo

    Usage example typo

    The usage example in Readme has an extra curly brace on line 4, it causes syntax error.

    buildscript {
        repositories {
                mavenCentral()
            }
        }
    
        dependencies {
            classpath 'com.andrewkroh.gradle:gradle-protobuf-plugin:0.2.0'
        } 
    }
    

    should be

    buildscript {
        repositories {
                mavenCentral()
        }
    
        dependencies {
            classpath 'com.andrewkroh.gradle:gradle-protobuf-plugin:0.2.0'
        } 
    }
    
    bug 
    opened by silvpol 0
  • Incompatible with the Android Plugin

    Incompatible with the Android Plugin

    This project seems to have the project found here: https://github.com/aantono/gradle-plugin-protobuf/issues/12

    Anyone know how to incorporate this into an android project?

    question 
    opened by danem 0
  • Add a sourceSet for generated code

    Add a sourceSet for generated code

    The plugin should add a new sourceSet for the generated code so that it is automatically incorporated into your IDE. I will also address that in the next release.

    As a workaround you can add a sourceSet yourself. This will get the source into your IDE, but it does not wire up a dependency on the compileProto task.

    sourceSets {
      generated {
        java.srcDirs += "$buildDir/$protobuf.outputJava"
      }
    }
    
    enhancement 
    opened by andrewkroh 0
Owner
Andrew Kroh
Andrew Kroh
gradle-android-scala-plugin adds scala language support to official gradle android plugin

gradle-android-scala-plugin gradle-android-scala-plugin adds scala language support to official gradle android plugin. See also sample projects at htt

saturday06 345 Dec 10, 2022
Ownership-gradle-plugin - Gradle code ownership verification plugin

Gradle code ownership verification plugin A gradle plugin that will verify owner

null 4 Dec 15, 2022
Helper to upload Gradle Android Artifacts, Gradle Java Artifacts and Gradle Kotlin Artifacts to Maven repositories (JCenter, Maven Central, Corporate staging/snapshot servers and local Maven repositories).

GradleMavenPush Helper to upload Gradle Android Artifacts, Gradle Java Artifacts and Gradle Kotlin Artifacts to Maven repositories (JCenter, Maven Cen

 Vorlonsoft LLC 21 Oct 3, 2022
GPP is Android's unofficial release automation Gradle Plugin. It can do anything from building, uploading, and then promoting your App Bundle or APK to publishing app listings and other metadata.

Gradle Play Publisher Gradle Play Publisher is Android's unofficial release automation Gradle Plugin. It can do anything from building, uploading, and

null 3.9k Dec 30, 2022
A Gradle plugin to report the number of method references in your APK on every build.

Dexcount Gradle Plugin A Gradle plugin to report the number of method references in your APK, AAR, or java module. This helps you keep tabs on the gro

Keepsafe 3k Dec 29, 2022
Gradle plugin which downloads and manages your Android SDK.

DEPRECATED This plugin is deprecated and is no longer being developed. Tools and dependencies are automatically downloaded using version 2.2.0 of the

Jake Wharton 1.4k Dec 29, 2022
A Gradle plugin to support the Groovy language for building Android apps

Groovy language support for Android Deprecated: This plugin has been deprecated in favor of Kotlin which has the full support of JetBrains and Google.

Groovy programming language 853 Dec 21, 2022
Add a different ribbon to each of your Android app variants using this gradle plugin. Of course, configure it as you will

Easylauncher gradle plugin for Android Modify the launcher icon of each of your app-variants using simple gradle rules. Add ribbons of any color, over

Mikel 960 Dec 18, 2022
A Gradle Plugin that removes unused resources in Android projects.

#Lint Cleaner Plugin Removes unused resources reported by Android lint including strings, colors and dimensions. Depracated As of Android Studio 2.0+

Marco RS 705 Nov 25, 2022
Gradle plugin which validates the licenses of your dependency graph match what you expect

Licensee ?? ?? A Gradle plugin which validates the licenses of your dependency graph match what you expect, or it fails your build! Jump to: Introduct

Cash App 506 Jan 8, 2023
IntelliJ plugin that provides some useful utilities to support the daily work with Gradle.

IntelliJ Gradle Utilities Plugin This IntelliJ plugin provides some useful utilities to support the daily work with Gradle. It's available on the offi

Marcel Kliemannel 6 Jul 29, 2022
Gradle plugin which helps you analyze the size of your Android apps.

Ruler Ruler is a Gradle plugin which helps you analyze the size of your Android apps. Motivation App size is an important metric which directly correl

Spotify 913 Dec 28, 2022
A Gradle plugin for providing your secrets to your Android project.

Secrets Gradle Plugin for Android A Gradle plugin for providing your secrets securely to your Android project. This Gradle plugin reads secrets from a

Google 560 Jan 8, 2023
Gradle plugin to use git tags as project version names

Version Name Gradle Plugin This plugin adds a kotlin extension function that provides a version name based on the latest git tag. How to use it ?? App

Doist 3 Mar 9, 2022
CKlib is a gradle plugin that will build and package C/C++/Objective-C code for Kotlin/Native.

C Klib CKlib is a gradle plugin that will build and package C/C++/Objective-C code for Kotlin/Native. The Problem When you want to access C-etc code f

Touchlab 73 Nov 8, 2022
Gradle plugin to help use create project

Infra-Gradle-Plugin 该插件旨在简化 Gradle 项目配置,几行代码就可以迅速开始一个项目, 仅支持 Kotlin DSL, Groovy 未测试! 引入插件 plugins { id("com.labijie.infra") version "your version"

Red Sparrow 0 Dec 23, 2021
A Mindustry modding gradle plugin, named Plumy.

Mindustry Gradle Plugin A Mindustry gradle plugin, named Plumy. Homepage Features Manage the Dependencies Download the Game Debug your Mod Work with O

Plumy Games 13 Sep 3, 2022
A gradle plugin to optimize built jars through individual file optimizations and increased compression

Machete Machete is a gradle plugin that attempts to optimize the size of output JARs through both individual file optimizations and overall compressio

Silver 9 Nov 2, 2022