Skip to content

Instantly share code, notes, and snippets.

@cristianovagos
Created September 26, 2019 11:22
Show Gist options
  • Save cristianovagos/7da54f58cca326ae7ef79a519752649e to your computer and use it in GitHub Desktop.
Save cristianovagos/7da54f58cca326ae7ef79a519752649e to your computer and use it in GitHub Desktop.
Gradle build file to generate Java jar with Protobuf generated files
apply plugin: 'java'
apply plugin: "com.google.protobuf"
repositories {
maven { url "https://plugins.gradle.org/m2/" }
}
buildscript {
repositories {
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.10'
}
}
dependencies {
implementation "javax.annotation:javax.annotation-api:1.2"
implementation "io.grpc:grpc-protobuf-lite:1.16.1"
implementation "io.grpc:grpc-okhttp:1.16.1"
implementation "io.grpc:grpc-stub:1.16.1"
implementation "com.google.protobuf:protobuf-lite:3.0.1"
implementation "com.google.protobuf:protobuf-java:3.5.1"
implementation "com.google.api.grpc:googleapis-common-protos:0.0.3"
}
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:3.6.0"
}
plugins {
javalite { artifact = "com.google.protobuf:protoc-gen-javalite:3.0.0" }
grpc {
artifact = "io.grpc:protoc-gen-grpc-java:1.7.0"
}
}
generateProtoTasks {
all().each { task ->
task.builtins {
// In most cases you don’t need the full Java output
// if you use the lite output.
remove java
}
task.plugins {
javalite {}
grpc { option 'lite' }
}
}
}
generatedFilesBaseDir = "$projectDir/genproto/java/src"
}
sourceSets {
main {
proto {
srcDirs "."
exclude 'build/**'
exclude 'genproto/**'
exclude 'vendor/**'
}
}
}
task todosJar(type: Jar) {
from(sourceSets.main.output) {
include "com/**"
include "luggit/todos/**"
}
archiveName "todos.jar"
}
jar.dependsOn todosJar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment