marcoferrer / kroto-plus

gRPC Kotlin Coroutines, Protobuf DSL, Scripting for Protoc
Apache License 2.0
494 stars 28 forks source link

Unresolved references to methods #50

Closed davidbilik closed 5 years ago

davidbilik commented 5 years ago

I have a problem in buildtime with generated code, it seems to be using different naming of method names on a Grpc service than there actually is. I have a proto file like

service BookService {
    // Book detail
    rpc getBook (GetBookRequest) returns (Book) {}
}

and the generated BookServiceGrpc contains method

 public void getBook(com.book.BookOuterClass.GetBookRequest request,
        io.grpc.stub.StreamObserver<com.book.BookOuterClass.Book> responseObserver) {
    ... 
}

but generated file from kroto have this method

suspend fun BookServiceStub.getBook(request: BookOuterClass.GetBookRequest =
        BookOuterClass.GetBookRequest.getDefaultInstance()): BookOuterClass.Book =
        clientCallUnary(request, BookServiceGrpc.getGetBookMethod())

and the problem is in getGetBookMethod. There is no such method and it fails with Unresolved reference: getGetBookMethod i cant find anything about it in config. Am I doing something wrong? I've tried also another library for kotlin + coroutines (https://github.com/rouzwawi/grpc-kotlin) and the build problem was the same

Note - I am using this in Android project with protobuf-lite, here is my config:

    implementation ("javax.annotation:javax.annotation-api:1.2")
    implementation("com.google.protobuf:protobuf-lite:3.0.1")

    implementation("io.grpc:grpc-core:1.16.1")
    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.github.marcoferrer.krotoplus:kroto-plus-coroutines:0.3.0")
    implementation ("com.github.marcoferrer.krotoplus:kroto-plus-test:0.3.0")
    implementation ("com.github.marcoferrer.krotoplus:kroto-plus-message:0.3.0")
protobuf {
    protoc {
        artifact = 'com.google.protobuf:protoc:3.6.1'
    }
    plugins {
        grpc {
            artifact = 'io.grpc:protoc-gen-grpc-java:1.0.0-pre2'
        }
        javalite {
            artifact = 'com.google.protobuf:protoc-gen-javalite:3.0.0'
        }
        kroto {
            artifact = "com.github.marcoferrer.krotoplus:protoc-gen-kroto-plus:0.3.0:jvm8@jar"
        }
    }
    generateProtoTasks {
        def krotoConfig = file("krotoconfig.asciipb") // Or .json
        all()*.plugins {
            javalite {}
        }
        ofNonTest()*.plugins {
            grpc {
                // Options added to --grpc_out
                option 'lite'
            }
            kroto {
                outputSubDir = "java"
                option "ConfigPath=$krotoConfig"
            }
        }
    }
}
davidbilik commented 5 years ago

I've figured it out, I had some old dependency versions

marcoferrer commented 5 years ago

On a separate note, you might want to remove the default java configuration if using java lite. The Gradle protobuf plugin adds it implicitly. It’s mentioned in more detail here. https://github.com/google/protobuf-gradle-plugin/blob/master/README.md#default-outputs

Also if you are using the kroto dslmarker option you’ll want to make sure you set your kroto out to javalite not java

        all()*.builtins(){
            remove java
        }
        ofNonTest()*.plugins {
            grpc {
                // Options added to --grpc_out
                option 'lite'
            }
            kroto {
                outputSubDir = "javalite"
                option "ConfigPath=$krotoConfig"
            }
        }