skip to Main Content

I’m trying to generate classes for my grpc client in kotlin but it only generates one class I’m following this tutorial link I already have protoc installed on my ubuntu I will post how is the protoc-gen-grpc-kotlin.sh and my proto. If anyone knows where I’m going wrong, I’d appreciate it.

my protoc-gen-grpc-kotlin.sh:

#!/usr/bin/bash

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
java -jar $DIR/protoc-gen-grpc-kotlin-1.3.0-jdk8.jar $@

I am using protoc-gen-grpc-kotlin-1.3.0-jdk8.jar plugin

My java version is 17 but I tested it with version 8 and it didn’t work either

My HelloService.proto:

syntax = "proto3";
package com.example.grpc;
option java_multiple_files = true;
//import "google/api/annotations.proto";

message HelloRequest {
    string firstName = 1;
    string lastName = 2;
}

message HelloResponse {
    string greeting =1;
}

service HelloService {
    rpc hello (HelloRequest) returns (HelloResponse) {}
//    rpc hello(HelloRequest) returns (HelloResponse){
//        option (google.api.http) = {
//            post: "/demo/item"
//            body: "*"
//        };
//    }
}

protoc command:

protoc --kotlin_out=. --java_out=. --plugin=protoc-gen-kotlin=protoc-gen-grpc-kotlin.sh --proto_path=. HelloService.proto

Java classes are normally generated but Create only one kotlin service

Thanks!

2

Answers


  1. It sounds like you’re not correctly compiling or generating the Java proto and gRPC classes that are necessary to use gRPC for Kotlin. It is normal and expected that the code you’ve shown should only generates one Kotlin file.

    (If you’re looking for Kotlin DSLs for your proto messages etc., that’s a separate feature of protobuf, not gRPC.)

    Login or Signup to reply.
  2. You also need to run protoc with the java plugin to generate the Java classes. Something like:

    protoc --java_out=. --plugin=protoc-gen-java=protoc-gen-grpc-java.sh --proto_path=. HelloService.proto
    protoc --kotlin_out=. --plugin=protoc-gen-kotlin=protoc-gen-grpc-kotlin.sh --proto_path=. HelloService.proto
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search