Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kotlin protos #266

Merged
merged 9 commits into from
Oct 13, 2021
Merged

kotlin protos #266

merged 9 commits into from
Oct 13, 2021

Conversation

jamesward
Copy link
Collaborator

No description provided.

@xmlking
Copy link

xmlking commented Sep 4, 2021

How to add an item to repeated field?
getting compilation error with following examples

Cannot access class 'com.google.protobuf.kotlin.DslList'. Check your module classpath for missing or conflicting dependencies
val request = linkRequest {
    profile = Profile.PROFILE_RO
    this.person = person
    addresses += address
}
val request = linkRequest {
    profile = Profile.PROFILE_RO
    this.person = person
    addresses.add(address)
}

@xmlking
Copy link

xmlking commented Sep 5, 2021

Resolved above issue.
I had to add implementation("com.google.protobuf:protobuf-kotlin:3.17.+") gradle dependency even though I am not explicitly using any classes in package com.google.protobuf.kotlin.*

This is a good point to document

    implementation(libs.protobuf.java)
    implementation(libs.protobuf.kotlin)

xmlking added a commit to xmlking/micro-apps that referenced this pull request Sep 5, 2021
@jamesward jamesward requested a review from bshaffer October 7, 2021 17:15
@jamesward jamesward added this to the 1.2.0 milestone Oct 11, 2021
Copy link
Contributor

@bshaffer bshaffer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Talked offline, but I think we need to update the gRPC hello world to include the proto dependency as well.

I'd also like to see a note somewhere like "The kotlin grpc library is stand-alone and does not depend on the proto-kotlin library, but they are best used together" or something along those lines.

@jamesward
Copy link
Collaborator Author

I updated the compiler docs with the Kotlin Protos stuff:
https://github.com/grpc/grpc-kotlin/blob/0a9dc03b1292264a317d499659cafa600fae0230/compiler/README.md

Hopefully that resolves the questions around this and clarifies that you can use both the gRPC Kotlin compiler and the Proto Kotlin compiler together (as we do in these examples) but you don't have to.

@jamesward jamesward merged commit f834a3c into master Oct 13, 2021
@jamesward jamesward deleted the kotlin-protos branch October 13, 2021 03:06
@Kernald
Copy link
Contributor

Kernald commented Jul 18, 2022

Am I correct to assume that this doesn't support proto-lite? The gRPC macro takes in a flavor argument that's pretty much just forwarded to the Java gRPC library, and picks the correct dependency depending on the flavor. Should a similar thing be done here as well?

@jamesward
Copy link
Collaborator Author

Today there isn't much difference with the Kotlin lite protos but you can use them:
https://github.com/grpc/grpc-kotlin/blob/master/examples/stub-lite/build.gradle.kts#L49-L64

The Java protos are pretty different though. And you do need to set the lite deps when using the lite protos:
https://github.com/grpc/grpc-kotlin/blob/master/examples/stub-lite/build.gradle.kts#L18-L20

@Kernald
Copy link
Contributor

Kernald commented Jul 18, 2022

The question was about the Bazel integration, sorry I wasn't clear, I didn't look closely at what this PR was adding (just noted it added the Bazel kt_jvm_proto_library macro) - specifically, kt_jvm_proto_library not having a flavor argument. Which ends up generating a library that always depends on the regular Java proto library, with no way to target the lite one.

@jamesward
Copy link
Collaborator Author

Ah, yeah I'm not sure on the Bazel side. Maybe @aragos has some info on that.

@Kernald
Copy link
Contributor

Kernald commented Jul 18, 2022

I just tried a fairly simple patch locally which seems to be working just fine - I'll send a PR very soon.

@Kernald
Copy link
Contributor

Kernald commented Jul 18, 2022

PR opened, #350

@blockjon-dd
Copy link

Hi @jamesward - if I do something like this:

bazel build //examples/protos/src/main/proto/io/grpc/examples/helloworld:hello_world_kt_grpc

Should the resulting .jar file contain the classes that allow me to actually instantiate an instance of HelloRequest and HelloReply? Or, do I need to rely on the java classes for that?

@blockjon-dd
Copy link

blockjon-dd commented Jan 9, 2025

I'm not seeing the example HelloRequest and HelloReply files that I would expect:

jon.block@DQK62VCYHR grpc-kotlin % bazel build //examples/protos/src/main/proto/io/grpc/examples/helloworld:hello_world_kt_grpc
Starting local Bazel server and connecting to it...
INFO: Analyzed target //examples/protos/src/main/proto/io/grpc/examples/helloworld:hello_world_kt_grpc (121 packages loaded, 2306 targets configured).
INFO: Found 1 target...
Target //examples/protos/src/main/proto/io/grpc/examples/helloworld:hello_world_kt_grpc up-to-date:
  bazel-bin/examples/protos/src/main/proto/io/grpc/examples/helloworld/hello_world_kt_grpc.jar
  bazel-bin/examples/protos/src/main/proto/io/grpc/examples/helloworld/hello_world_kt_grpc.jdeps
INFO: Elapsed time: 5.585s, Critical Path: 0.41s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
jon.block@DQK62VCYHR grpc-kotlin % unzip -l bazel-bin/examples/protos/src/main/proto/io/grpc/examples/helloworld/hello_world_kt_grpc.jar
Archive:  bazel-bin/examples/protos/src/main/proto/io/grpc/examples/helloworld/hello_world_kt_grpc.jar
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  01-01-2010 00:00   META-INF/
      182  01-01-2010 00:00   META-INF/MANIFEST.MF
       24  01-01-2010 00:00   META-INF/examples_protos_src_main_proto_io_grpc_examples_helloworld-hello_world_kt_grpc.kotlin_module
        0  01-01-2010 00:00   io/
        0  01-01-2010 00:00   io/grpc/
        0  01-01-2010 00:00   io/grpc/examples/
        0  01-01-2010 00:00   io/grpc/examples/helloworld/
     2339  01-01-2010 00:00   io/grpc/examples/helloworld/GreeterGrpcKt$GreeterCoroutineImplBase$bindService$1.class
     4336  01-01-2010 00:00   io/grpc/examples/helloworld/GreeterGrpcKt$GreeterCoroutineImplBase.class
     1988  01-01-2010 00:00   io/grpc/examples/helloworld/GreeterGrpcKt$GreeterCoroutineStub$sayHello$1.class
     5081  01-01-2010 00:00   io/grpc/examples/helloworld/GreeterGrpcKt$GreeterCoroutineStub.class
     2174  01-01-2010 00:00   io/grpc/examples/helloworld/GreeterGrpcKt.class
---------                     -------
    16124                     12 files
    ```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants