Skip to content

Instantly share code, notes, and snippets.

@shaokeyibb
Last active July 16, 2023 14:18
Show Gist options
  • Save shaokeyibb/52dcc2798062ad0b04b02a03004e8ac2 to your computer and use it in GitHub Desktop.
Save shaokeyibb/52dcc2798062ad0b04b02a03004e8ac2 to your computer and use it in GitHub Desktop.
grpc configuration with gradle kotlin dsl
// refer:
// https://github.com/yidongnan/grpc-spring-boot-starter/blob/master/examples/grpc-lib/build.gradle
// https://github.com/grpc/grpc-java/blob/master/examples/build.gradle
plugins {
id("java")
id("com.google.protobuf") version "0.9.1"
}
// Don't forget to modify the version to latest!
val grpcVersion = "1.56.1"
val protobufVersion = "3.22.3"
val protocVersion = protobufVersion
repositories {
maven { url = uri("https://maven-central.storage-download.googleapis.com/maven2/") } // optional
mavenCentral()
mavenLocal()
}
dependencies {
implementation("io.grpc:grpc-protobuf:${grpcVersion}")
implementation("io.grpc:grpc-services:${grpcVersion}")
implementation("io.grpc:grpc-stub:${grpcVersion}")
implementation("javax.annotation:javax.annotation-api:1.3.2")
runtimeOnly("io.grpc:grpc-netty-shaded:${grpcVersion}")
}
protobuf {
protoc { artifact = "com.google.protobuf:protoc:${protocVersion}" }
plugins {
register("grpc") {
artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}"
}
}
generateProtoTasks {
this.all().forEach {
it.plugins {
register("grpc")
}
}
}
}
sourceSets {
main {
java {
srcDirs("build/generated/source/proto/main/grpc")
srcDirs("build/generated/source/proto/main/java")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment