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

Quarkus gRPC generator tries to write the same file twice #25275

Closed
scrocquesel opened this issue Apr 29, 2022 · 11 comments · Fixed by #30646
Closed

Quarkus gRPC generator tries to write the same file twice #25275

scrocquesel opened this issue Apr 29, 2022 · 11 comments · Fixed by #30646
Labels
area/grpc gRPC kind/bug Something isn't working
Milestone

Comments

@scrocquesel
Copy link
Contributor

Describe the bug

Trying to generate service/message definition from https://github.com/envoyproxy/java-control-plane/tree/main/api produces "Tried to write the same file twice" errors.

Expected behavior

Should compile

Actual behavior

Error

[INFO] --- quarkus-maven-plugin:2.8.2.Final:generate-code (default) @ grpc ---
udpa/type/v1/typed_struct.proto:14:1: warning: Import validate/validate.proto is unused.
udpa/service/orca/v1/orca.proto:18:1: warning: Import validate/validate.proto is unused.
xds/type/v3/typed_struct.proto:10:1: warning: Import validate/validate.proto is unused.
xds/service/orca/v3/orca.proto:14:1: warning: Import validate/validate.proto is unused.
io/envoyproxy/envoy/service/accesslog/v3/AccessLogService.java: Tried to write the same file twice.
io/envoyproxy/envoy/service/accesslog/v2/AccessLogService.java: Tried to write the same file twice.
io/envoyproxy/envoy/service/auth/v3/Authorization.java: Tried to write the same file twice.
io/envoyproxy/envoy/service/auth/v2/Authorization.java: Tried to write the same file twice.
io/envoyproxy/envoy/service/auth/v2alpha/Authorization.java: Tried to write the same file twice.
io/envoyproxy/envoy/service/discovery/v3/AggregatedDiscoveryService.java: Tried to write the same file twice.
io/envoyproxy/envoy/service/discovery/v2/RuntimeDiscoveryService.java: Tried to write the same file twice.
io/envoyproxy/envoy/service/discovery/v2/SecretDiscoveryService.java: Tried to write the same file twice.
io/envoyproxy/envoy/service/discovery/v2/AggregatedDiscoveryService.java: Tried to write the same file twice.
io/envoyproxy/envoy/service/discovery/v2/HealthDiscoveryService.java: Tried to write the same file twice.
....

How to Reproduce?

copy/pasting the proto folder from the given repo or using dependency :

quarkus.generate-code.grpc.scan-for-proto=io.envoyproxy.controlplane:api
<dependency>
      <groupId>io.envoyproxy.controlplane</groupId>
      <artifactId>api</artifactId>
      <version>0.1.31</version>
</dependency>

Output of uname -a or ver

No response

Output of java -version

No response

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.8.2

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

Removing --q-grpc_out=/grpc/target/generated-sources/grpc from the generated command line works.

@scrocquesel scrocquesel added the kind/bug Something isn't working label Apr 29, 2022
@quarkus-bot quarkus-bot bot added the area/grpc gRPC label Apr 29, 2022
@quarkus-bot
Copy link

quarkus-bot bot commented Apr 29, 2022

/cc @cescoffier, @michalszynkiewicz

@scrocquesel
Copy link
Contributor Author

Find out that it fails when the proto file contains

option java_generic_services = true;

I guess it is because the mutiny generator is producing its own implementation and it collides. I don't know if it can be disable from command line but this is an issue for me as I don't have ownership of those proto files and can be an issue when generating from jar file.

@michalszynkiewicz
Copy link
Member

Did you try maven or gradle plugin as a workaround?

@scrocquesel
Copy link
Contributor Author

maven plugin alone works but all I got is the com.google.protobuf.Service implementation of service and not the Mutiny one.

@scrocquesel
Copy link
Contributor Author

scrocquesel commented Jan 25, 2023

Worked if the MutinyGrpcGenerator is run in a second step alone.
Another solution would be to able to preprocess all .proto files to remove or comment line containing java_generic_services.

@cescoffier
Copy link
Member

I need to check what java_generic_services is actually doing.

@scrocquesel
Copy link
Contributor Author

@cescoffier it generates a Greeter.java file with an abstract service class. It has been deprecated since plug-ins has been introduced and should not be used anymore.
The mutiny plugin does exactly what it should by providing a custom implementation of the same name.
When using plugin to generate service, developer should remove the generic service but it's not possible when you dont have control on proto files, especially when importing them from a package dependency. Maybe only those imported proto files should be preprocessed.

@cescoffier
Copy link
Member

Thanks @scrocquesel.
Yes, we may need to pre-process the files when we handle the mutiny generation.

@alesj WDYT?

@alesj
Copy link
Contributor

alesj commented Jan 26, 2023

@cescoffier pre-process them how? Or about which files are we talking exactly?

@scrocquesel
Copy link
Contributor Author

@cescoffier pre-process them how? Or about which files are we talking exactly?

Actually, files that are added to src/proto can be modified by the developer maybe we can intercept the output and provide a meaningful message if it happens.
Files that are fetch from a package dependency should be modified first.

Let me know what could be the best solution and I'll try to implement it.

@scrocquesel
Copy link
Contributor Author

@alesj Have a look to the draft PR. It work in my case but there is a branch in the extractProtosFromArtifact I don't know when it goes through. Is it for import only ?

Also, intercepting the output would add boilerplate complexity. Maybe just add a note in the documentation would be enough as it should not be common nowadays.

gsmet added a commit that referenced this issue Jan 31, 2023
Force java_generic_services to false for protos gathered from dependencies
@quarkus-bot quarkus-bot bot added this to the 2.17 - main milestone Jan 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/grpc gRPC kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants