question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

gRPC code generation for specific dependencies

See original GitHub issue

Description

gRPC users are encouraged to share .proto files instead of generated code, as the other way around defeats the purpose of schema first contract. Both client and server should use the same .proto file to be able to communicate.

My opinion is that the most common way of sharing .proto files is between modules in a multi-module project. In this case, Quarkus does not provide any config or way to register the .proto files for code generation or discovery.

Given the following project structure:

example-parent
|
|- example-security-api
|- example-audit-api
|- example-common-api
|- example-security-service
|- example-audit-service
|- example-service

The -api modules contain only .proto files to be used between services, because you manage your .proto files at a single place and you don’t need to copy the files from one service to another. The security service uses the same .proto files to implement the security API server part and the example service uses the same .proto files to generate the client. In this common scenario, even if you set quarkus.generate-code.grpc.scan-for-imports to all, nothing is generated. IntelliJ doesn’t even let you run the project. Please note that the service modules have no .proto files whatsoever and adding jandex index doesn’t help either. Users resort to using the generated code because copy-pasting the .proto files in the same project in multiple modules is error prone.

Quarkus should provide a way for code generation for this scenario, without sharing the actual code, but using the .proto files and it should be documented in the guides.

Implementation ideas

My proposal is to add configuration similar to quarkus.index-dependency which will run code generation on a given dependency based on the .proto files found in the dependency. This way we will avoid scanning the whole classpath and it will work for both local and remote dependencies. The configuration can also ask input from the developer for the actual path where the .proto files reside in the dependency. When specifying a dependency, version shouldn’t be provided. Maybe we can make artifactId optional too. Developer would require setting the correct configuration and making sure that the .proto files are actually packaged in the jar output for code generation to work.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
kristijan-rusucommented, Jan 4, 2022

@michalszynkiewicz Here is simplest reproducer I could make. If you want to test the implementation with generated code, uncomment the extension and plugins part of the example-api maven pom. org.example.zip

0reactions
michalszynkiewiczcommented, Feb 2, 2022

I ended up with a solution specific to gRPC but implementing it for other providers shouldn’t be that hard now

Read more comments on GitHub >

github_iconTop Results From Across the Web

Generated-code reference | Java - gRPC
The generated Java code contains an inner abstract class suffixed with ImplBase , such as ServiceNameImplBase . This class defines one Java ...
Read more >
Getting Started with gRPC - Quarkus
Protocol Buffers specification provides a way to import proto files. The Quarkus code generation mechanism lets you control the scope of dependencies to...
Read more >
Packaging Generated Code for gRPC Services - Bugsnag
Learn how we package generated code from Protocol Buffer files to have a simple way to create, modify and integrate gRPC services.
Read more >
Go Generated Code | Protocol Buffers - Google Developers
This page describes exactly what Go code the protocol buffer compiler generates for any given protocol definition.
Read more >
Using gRPC and ProtoBuf in Java - Medium
We define the service protobuf file and add the required dependencies in pom.xml to compile the proto files and generate RPC Java interfaces...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found