Writing a gradle task to generate gRPC files for java and javascript

152 views Asked by At

I'm new to gradle and I would like to generate gRPC files for both java, javascript and typescript from a single build.gradle file. However, I can generate the proto files for messages in both java and javascript but for the service it can only generate either java or javascript files and not both.

Below is my gradle file. Since I have configured path variable, it only considers the grpc plugin for node and generates the javascript service file and skips the java part.

Please note that I have tried to seperate them into different gradle files and due to requirements of my repository, I need to merge them into a single gradle file.

protobuf {
  // Configure the protoc executable
  protoc { artifact = "com.google.protobuf:protoc:${protocVersion}" }

  plugins {
      grpc { 
        // Configure the gRPC Java plugin
        artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}" 

        // Configure the gRPC node plugin
        path = file(
        './node_modules/.bin/grpc_tools_node_protoc_plugin' + (isWindows ? '.cmd' : '')
        )
      }
      ts {
        path = file(
          './node_modules/.bin/protoc-gen-ts' + (isWindows ? '.cmd' : '')
      )
    }
  }
  generateProtoTasks {
    all().each { task ->
      task.plugins {
        grpc {
          outputSubDir = 'js'
          option 'grpc_js'
        }
        ts {
          option 'service=grpc-node,mode=grpc-js'
        }
      }
      task.builtins {
        js {
          option 'import_style=commonjs'
        }
      }
      task.dependsOn runNpmInstall
    }
  }
}
0

There are 0 answers