Skip to content

Instantly share code, notes, and snippets.

@nguyensinhtu
Created April 5, 2022 08:26
Show Gist options
  • Save nguyensinhtu/8a26b26568f3721c3d550ecbc8f022d0 to your computer and use it in GitHub Desktop.
Save nguyensinhtu/8a26b26568f3721c3d550ecbc8f022d0 to your computer and use it in GitHub Desktop.

Revisions

  1. nguyensinhtu created this gist Apr 5, 2022.
    115 changes: 115 additions & 0 deletions build_with_protobuf.gradle
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,115 @@
    buildscript {
    ext {
    grpcVersion = "1.39.0"
    protobufVersion = "3.17.3"
    protoGenValidateVersion = "0.4.1"
    }
    }

    plugins {
    id "com.google.protobuf" version "0.8.16"
    id "java"
    id "maven-publish"
    id "idea"

    }

    group = "my_group"

    sourceSets {
    main {
    proto {
    srcDirs 'schema/proto'
    include '**/*.protodevel'
    }
    java {
    srcDirs 'java/main/grpc'
    srcDirs 'java/main/java'
    }
    }
    }

    idea {
    module {
    sourceDirs += file("${projectDir}/schema/proto")
    }
    }

    repositories {
    mavenCentral()
    jcenter()
    }

    protobuf {
    protoc {
    artifact = "com.google.protobuf:protoc:${protobufVersion}"
    }
    plugins {
    grpc {
    artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}"
    }
    javapgv {
    artifact = "io.envoyproxy.protoc-gen-validate:protoc-gen-validate:${protoGenValidateVersion}"
    }
    }

    generateProtoTasks {
    all()*.plugins {
    grpc {}
    javapgv {
    option "lang=java"
    }
    }
    }
    generatedFilesBaseDir = "${projectDir}/java"
    }

    dependencies {
    implementation "io.grpc:grpc-netty:${grpcVersion}"
    implementation "io.grpc:grpc-protobuf:${grpcVersion}"
    implementation "io.grpc:grpc-stub:${grpcVersion}"
    implementation "com.google.protobuf:protobuf-java:${protobufVersion}"
    implementation "io.envoyproxy.protoc-gen-validate:pgv-java-stub:${protoGenValidateVersion}"
    implementation "javax.annotation:javax.annotation-api:1.3.2"
    protobuf "com.google.protobuf:protobuf-java:${protobufVersion}"
    }

    sourceSets {
    main {
    proto {
    srcDirs "schema/proto"
    }
    java {
    srcDirs "java/main/grpc"
    srcDirs "java/main/java"
    }
    }
    }

    publishing {
    repositories {
    maven {
    name = "GitHubPackages"
    url = uri("${url_to_publish_package}")
    credentials {
    username = System.getenv("GITHUB_USERNAME")
    password = System.getenv("GITHUB_TOKEN")
    }
    }
    }
    publications {
    gpr(MavenPublication) {
    from(components.java)
    }
    }
    }

    java {
    withSourcesJar()
    }

    jar {
    from {
    configurations.runtimeClasspath.filter { it.exists() }.collect { it.isDirectory() ? it : zipTree(it) }
    }
    }