2

I try to compile proto definitions into kotlin stubs, but get import issues. My gradle is


protobuf {
    protoc {
        artifact = "com.google.protobuf:protoc:3.21.2"
    }

    plugins {
        grpckt {
            artifact = "io.grpc:protoc-gen-grpc-kotlin:1.3.0:jdk8@jar"
        }
    }

    generateProtoTasks {
        all().forEach { task ->
            task.builtins {
                grpckt {
                    option 'lite'
                }
            }
            task.plugins {
                kotlin {
                    option 'lite'
                }
            }
        }
    }
}

dependencies {

    //grpc dependency
    implementation("io.grpc:grpc-kotlin-stub:1.3.0")
    implementation 'io.grpc:grpc-okhttp:1.47.0'
    implementation("io.grpc:grpc-protobuf:1.47.0")
    implementation("com.google.protobuf:protobuf-kotlin:3.21.12")
    implementation 'io.grpc:grpc-protobuf-lite:1.47.0'

}

I have few proto files. After proto compiled I get the files with import errors: enter image description here

option java_multiple_files = true - doesn`t help.

2 Answers 2

3

It might be too late, but for all those who found their way here through Google, you also need to generate Java source files to make this work.

protobuf {
    protoc { artifact = "com.google.protobuf:protoc:${protobufVersion}" }
    plugins {
        id("grpc") {
            artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}"
        }
        id("grpckt") {
            artifact = "io.grpc:protoc-gen-grpc-kotlin:${grpcKotlinVersion}:jdk8@jar"
        }
        id("java"){
            artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}"
        }
    }
    generateProtoTasks {
        all().forEach { task ->
            task.plugins {
                id("grpc") {
                    option("lite")
                }
                id("grpckt") {
                    option("lite")
                }
                id("java") {
                    option("lite")
                }
            }
            task.builtins {
                id("kotlin")
            }
        }
    }
}

dependencies {
    implementation("io.grpc:grpc-okhttp:${grpcVersion}")
    implementation("io.grpc:grpc-protobuf-lite:${grpcVersion}")
    implementation("io.grpc:grpc-stub:${grpcVersion}")
    implementation("io.grpc:grpc-kotlin-stub:${grpcKotlinVersion}")
    implementation("com.google.protobuf:protobuf-javalite:${protobufVersion}")
    implementation("com.google.protobuf:protobuf-kotlin-lite:${protobufVersion}")
}
0

You are configuring your proto generation in lite mode but not using the kotlin-lite library. That may be causing your issues.

Try replacing

implementation("com.google.protobuf:protobuf-kotlin:3.21.12")

with

implementation("com.google.protobuf:protobuf-kotlin-lite:3.21.12")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.