grpc / grpc-kotlin

Kotlin gRPC implementation. HTTP/2 based RPC
https://grpc.io/docs/languages/kotlin
Apache License 2.0
1.2k stars 165 forks source link

protoc-gen-grpckt is not recognized, on windows #320

Open diddiman opened 2 years ago

diddiman commented 2 years ago

Hi all

I am trying to generate some code from my protos, currently my build.gradle look like this

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id 'com.google.protobuf' version '0.8.18'
}

android {
    compileSdk 31

    defaultConfig {
        applicationId "com.example.foodshoppinglist"
        minSdk 23
        targetSdk 31
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
}
dependencies {
    compileOnly 'javax.annotation:javax.annotation-api:1.3.2'
    implementation("io.grpc:grpc-kotlin-stub:1.2.1")
    implementation("io.grpc:grpc-protobuf:1.44.0")
    implementation('com.google.protobuf:protobuf-kotlin:3.19.4')

    implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.appcompat:appcompat:1.4.1'
    implementation 'com.google.android.material:material:1.5.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

protobuf {
    protoc {
        artifact = "com.google.protobuf:protoc:3.19.4"
    }
    plugins {
        grpc {
            artifact = "io.grpc:protoc-gen-grpc-java:1.44.0"
        }
        grpck {
            artifact = "io.grpc:protoc-gen-grpc-kotlin:1.2.1"
        }
    }
    generateProtoTasks {
        all().forEach {
            it.plugins {
                grpc
                grpckt
            }
            it.builtins {
                "kotlin"
            }
        }
    }
}

I am running on windows 10, 64 bit. By no means i am any expert on this so i might be doing hundred of thing wrong. But when trying to rebuild project i get

Execution failed for task ':app:generateDebugProto'.
> protoc: stdout: . stderr: 'protoc-gen-grpckt' is not recognized as an internal or external command,
  operable program or batch file.
  --grpckt_out: protoc-gen-grpckt: Plugin failed with status code 1.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

Does anyone have any idea what's wrong? Is there a bug or am i just doing everything wrong?

jamesward commented 2 years ago

For the grpck artifact, try:

artifact = "io.grpc:protoc-gen-grpc-kotlin:1.2.1:jdk7@jar"
diddiman commented 2 years ago

Tried it now, seems to give the same error

jamesward commented 2 years ago

Odd. Can you try the examples and see if it works (ie ./gradlew :stub:build): https://github.com/grpc/grpc-kotlin/tree/master/examples

diddiman commented 2 years ago

That seems to work better:

PS C:\dev\grpc-kotlin\examples> ./gradlew :stub:build
Starting a Gradle Daemon, 1 incompatible and 1 stopped Daemons could not be reused, use --status for details

BUILD SUCCESSFUL in 24s
17 actionable tasks: 7 executed, 10 up-to-date
jamesward commented 2 years ago

Cool. How about from within Android Studio / IntelliJ?

diddiman commented 2 years ago

Do you mean that i should open a terminal in Android Studio and run in there? if yes

C:\dev\grpc-kotlin\examples>gradlew :stub:build

BUILD SUCCESSFUL in 2s
17 actionable tasks: 17 up-to-date
jamesward commented 2 years ago

Your original message made it seem like you were running the build from Android Studio (a menu). Can you run the build in the same way on the examples?

diddiman commented 2 years ago

That seems to work, hmmm

jamesward commented 2 years ago

Ok, so something different between the gradle setups. But it is hard to tell because of the differences between the groovy & kotlin build DSLs.

diddiman commented 2 years ago

I'm starting to copy the stuff from the example-setup that seems necessary. Let's see where i end up

pddg commented 2 years ago

@diddiman It may just be a typo, but isn't it grpck instead of grpckt?

↓ The following is an excerpt from the sample you provided.

    plugins {
        grpc {
            artifact = "io.grpc:protoc-gen-grpc-java:1.44.0"
        }
        grpck {
            artifact = "io.grpc:protoc-gen-grpc-kotlin:1.2.1"
        }
    }
JavierSegoviaCordoba commented 2 years ago

@jamesward I am unable to get this working.

Is it not possible to get a simpler setup for Gradle?

jamesward commented 2 years ago

@JavierSegoviaCordoba Here is a more basic project that might help you get things going: https://github.com/GoogleCloudPlatform/kotlin-samples/tree/main/run/grpc-hello-world-gradle

It also uses latest versions which changes some syntax in the build.