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

Remove grpc-protobuf dependency for stub runtime #234

Closed
devkanro opened this issue Feb 26, 2021 · 14 comments · Fixed by #250
Closed

Remove grpc-protobuf dependency for stub runtime #234

devkanro opened this issue Feb 26, 2021 · 14 comments · Fixed by #250
Milestone

Comments

@devkanro
Copy link

I found the grpc-kotlin-stub doesn't use any classes from grpc-protobuf/grpc-protobuf-lite, maybe we can use the grpc-api/grpc-stub instead?
Then we can just provide one package for both protobuf and protobuf-lite cases and for non-google official protobuf runtime cases.

jamesward added a commit that referenced this issue Feb 26, 2021
@jamesward
Copy link
Collaborator

I think we can do that and I gave it a try:
https://github.com/grpc/grpc-kotlin/tree/no-lite

Downside is that the user has to specify a protobuf dep, like:

api("io.grpc:grpc-protobuf:3.13.0")

And in the case of lite they have to also add a guava dep:

api("io.grpc:grpc-protobuf-lite:${rootProject.ext["grpcVersion"]}")
api("com.google.guava:guava:28.2-jre") // or `-android`

WDYT?

@devkanro
Copy link
Author

Looks good.
User has to specify a protobuf dep is not a downside I think, the grpc-kotlin-stub is not just can be used in google official protobuf runtime.

But I have some confusion for guava.
Why do we need api dep for guava in the lite case?
Do we use guava classes for grpc-kotlin-stub or generated codes?

I found there are runtimeOnly dep for guava in grpc-protobuf already, and there are no guava dep in grpc-kotlin-stub or grpc-kotlin-stub-lite now.

@jamesward
Copy link
Collaborator

The guava dep is transitive for io.grpc:grpc-api:

+--- io.grpc:grpc-stub:1.29.0
|    \--- io.grpc:grpc-api:1.29.0
|         +--- io.grpc:grpc-context:1.29.0
|         +--- com.google.errorprone:error_prone_annotations:2.3.4
|         +--- com.google.code.findbugs:jsr305:3.0.2
|         +--- org.codehaus.mojo:animal-sniffer-annotations:1.18
|         \--- com.google.guava:guava:28.2-android
|              +--- com.google.guava:failureaccess:1.0.1
|              +--- com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava
|              +--- com.google.code.findbugs:jsr305:3.0.2
|              +--- org.checkerframework:checker-compat-qual:2.5.5
|              +--- com.google.errorprone:error_prone_annotations:2.3.4
|              \--- com.google.j2objc:j2objc-annotations:1.3

But is marked as runtime. Not including it with stub-lite usage results in:

/home/jamesward/projects/grpc-kotlin/examples/stub-lite/build/generated/source/proto/main/grpc/io/grpc/examples/routeguide/RouteGuideGrpc.java:433: error: package com.google.common.util.concurrent does not exist
    public com.google.common.util.concurrent.ListenableFuture<io.grpc.examples.routeguide.Feature> getFeature(

We don't see this error with stub usage (in the examples) because the dependency on com.google.protobuf:protobuf-java-util brings it in transitively.

@devkanro
Copy link
Author

devkanro commented Feb 27, 2021

I found the reason for this problem is the version of grpc-stub is not match with grpc-api.

Before grpc-stub 1.30.0, the guava was a compile dep of grpc-api.
After the 1.30.0 version, the guava is a runtime dep for grpc-api, but it will be a compile dep for grpc-stub.

If you using a low version for grpc-stub but a high version for grpc-api, the problem will have happened.
Upgrade the grpc version of grpc-kotlin in ext can resolve this problem.

Snipaste_2021-02-27_19-06-00

Reference:
grpc/grpc-java@v1.30.0

Note: gRPC-Java no longer exposes many transitive dependencies as "compile" dependencies,
    but instead specifies them as "runtime" dependencies. Consuming projects using these
    dependencies directly will need to explicitly add the dependencies to their compile-time classpath.

@jamesward
Copy link
Collaborator

So maybe we should make the grpc-stub dependency in grpc-kotlin-stub non-transitive?

@devkanro
Copy link
Author

devkanro commented Mar 3, 2021

No, I think. The grpc-stub should be a compile dep for grpc-kotlin-stub.

  1. AbstractCoroutineStub extends from AbstractStub.
  2. Kotlin gRPC codes based on Java gRPC codes, and the Java gRPC codes need the grpc-stub classes.

@jamesward
Copy link
Collaborator

Looks like it might work to make the grpc-stub dependency provided so that it isn't transitive: https://github.com/grpc/grpc-kotlin/compare/no-lite#diff-483f493fdd56e587549eb080ba6af32d0f88765702675df3474f6e507ea612d3R31

@devkanro
Copy link
Author

devkanro commented Mar 5, 2021

Yes, it works. But I still think grpc-stub should be a api dep for grpc-kotlin-stub.

@jamesward
Copy link
Collaborator

Isn't that the source of the version incompatibilities though?

@devkanro
Copy link
Author

Ummm...How about upgrade grpc-stub version to match grpc-api?
In my opinion, the version of grpc-stub must be matched with grpc-api.

@jamesward
Copy link
Collaborator

If we include the grpc-stub dependency and make it transitive, then the versions do match, as long as there isn't another dependency that brings in a newer grpc-api.

@devkanro
Copy link
Author

devkanro commented Mar 12, 2021

Yes, and users do not need to add grpc-stub to their project in most case.
If users need to upgrade grpc-stub to a higher version than which gprc-kotlin-stub depend on, just add this grpc-stub to their build.gradle.

api("io.grpc:grpc-kotlin-stub:1.1.1")
api("io.grpc:grpc-stub:1.35.6")

@jamesward jamesward added this to the 1.0.1 milestone Apr 12, 2021
jamesward added a commit that referenced this issue Apr 19, 2021
@jamesward
Copy link
Collaborator

Finally getting the chance to come back to this. So I think we can do is make grpc-kotlin-stub have a transitive dependency on io.grpc:grpc-stub but not depend on grpc-protobuf, protobuf-java-util, io.grpc:grpc-protobuf-lite, or com.google.protobuf:protobuf-javalite.

That seems to be working and I've updated the no-lite branch to reflect the changes:
https://github.com/grpc/grpc-kotlin/compare/no-lite

Does that seem right?

@devkanro
Copy link
Author

Good work! just wait for the release.

jamesward added a commit that referenced this issue Apr 29, 2021
* try to remove stub-lite for #234

* try to non-transitive grpc-stub

* make grpc-stub transitive

* upgrade info

* tests need grpc-protobuf

* always publish to maven local

* fix links

* to kts

* doc cleanupp

* plain console

* add retry to arm tests

* Update CHANGELOG.md

Co-authored-by: Brent Shaffer <betterbrent@google.com>

Co-authored-by: Brent Shaffer <betterbrent@google.com>
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 a pull request may close this issue.

2 participants