protoc-jar-maven-plugin
protoc-jar-maven-plugin copied to clipboard
Cannot generate gRPC stubs with java-shaded configuration
Tried a dozen different configs and can't seem to get the gRPC stubs to compile. I need the shaded proto code to work with HBase
<dependency>
<groupId>com.github.os72</groupId>
<artifactId>protobuf-java-shaded-351</artifactId>
<version>0.9</version>
</dependency>
<dependency>
<groupId>com.github.os72</groupId>
<artifactId>protobuf-java-util-shaded-351</artifactId>
<version>0.9</version>
</dependency>
...
<plugin>
<groupId>com.github.os72</groupId>
<artifactId>protoc-jar-maven-plugin</artifactId>
<version>3.5.1</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<protocVersion>3.5.1</protocVersion>
<!-- <includeStdTypes>true</includeStdTypes> -->
<!-- <protocArtifact>com.google.protobuf:protoc:3.0.0</protocArtifact> -->
<protocArtifact>com.google.protobuf:protoc:3.5.1</protocArtifact>
<inputDirectories>
<include>src/main/proto</include>
</inputDirectories>
<outputTargets>
<outputTarget>
<type>java-shaded</type>
<outputDirectory>src/main/java</outputDirectory>
</outputTarget>
<outputTarget>
<type>grpc-java</type>
<outputDirectory>src/main/java</outputDirectory>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.16.1</pluginArtifact>
</outputTarget>
</outputTargets>
</configuration>
</execution>
</executions>
</plugin>
Output
[ERROR] XXX/src/main/java/com/x/proto/GeneratorGrpc.java:[50,64] method marshaller in class io.grpc.protobuf.ProtoUtils cannot be applied to given types;
[ERROR] required: T
[ERROR] found: com.x.proto.Empty
[ERROR] reason: inferred type does not conform to upper bound(s)
[ERROR] inferred: com.x.proto.Empty
[ERROR] upper bound(s): com.google.protobuf.Message
[ERROR] XXX/hbase/src/main/java/com/x/proto/GeneratorGrpc.java:[238,70] getServiceDescriptor() in com.x.proto.GeneratorGrpc.GeneratorBaseDescriptorSupplier cannot implement getServiceDescriptor() in io.grpc.protobuf.ProtoServiceDescriptorSupplier
[ERROR] return type com.github.os72.protobuf351.Descriptors.ServiceDescriptor is not compatible with com.google.protobuf.Descriptors.ServiceDescriptor
[ERROR] X/hbase/src/main/java/com/x/proto/GeneratorGrpc.java:[233,67] getFileDescriptor() in com.x.proto.DnsGeneratorGrpc.GeneratorBaseDescriptorSupplier cannot implement getFileDescriptor() in io.grpc.protobuf.ProtoFileDescriptorSupplier
I assume I have a version mismatch?
I don't think this has been tried before - shaded plus grpc. We might need a new type grpc-java-shaded and rewrite the grpc-generated code. This may be a relatively simple search-replace exercise, need to look. But we may also need a shaded grpc runtime
Would you be able to help? See how java-shaded is implemented
Ok, good to know. I'll take a look at java-shaded and see if it is something I understand enough to tackle.
One easy resolution I landed on though for my specific use case (HBase 1.x depending on Protobuf 2 while needing Proto3 + gRPC) was moving up to HBase 2 which resolves the underlying proto dependency directly.
I'm also seeing that a grpc-protobuf-shaded would be helpful alongside grpc-netty-shaded. I'm having issues using newer gRPC versions in a project due to inclusion of io.kubernetes:client-java's conflicting protobuf-java versions.
The feature would be quite complex to implement Would you consider sponsoring/donating to the project?