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
Is it possible to generate CPP GRPC Stub Code using plugin? #25
Comments
Hello Adam, First of all, apologies for a slow response, I have been snowed under with work in the last few weeks. To your question. I think what you are trying to achieve is quite feasible (even if Maven is not the best tool for dealing with non-JVM languages). Unlike protoc-gen-grpc-java that Google distributes through Maven Central, Assuming you still need to generate and compile Java sources as well, you will need to introduce separate plugin executions as follows: <build>
<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.4.1.Final</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.5.0</version>
<configuration>
<protocArtifact>com.google.protobuf:protoc:3.2.0:exe:${os.detected.classifier}</protocArtifact>
</configuration>
<executions>
<execution>
<id>protoc-java</id>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>protoc-cpp</id>
<goals>
<goal>compile-cpp</goal>
</goals>
</execution>
<execution>
<id>protoc-grpc-java</id>
<goals>
<goal>compile-custom</goal>
</goals>
<configuration>
<pluginId>grpc-java</pluginId>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.3.0:exe:${os.detected.classifier}</pluginArtifact>
</configuration>
</execution>
<execution>
<id>protoc-grpc-cpp</id>
<goals>
<goal>compile-custom</goal>
</goals>
<configuration>
<pluginId>grpc-cpp</pluginId>
<!-- You may need to run `which grpc_cpp_plugin` beforehand to determine the actual path-->
<pluginExecutable>grpc_cpp_plugin</pluginExecutable>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build> Please note that the above assumes conventional defaults for all executions, and you may want to customise source or target directories, or any other relevant parameters. Please give it a go and let me know if it works for you. Kind regards, |
Hi Sergei, I can confirm these instructions work! Hopefully this will help anyone in the future who has a maven build system. THANK YOU SO MUCH! Adam |
Hi Sergei/adam, This help me now :) I was trying to use plugin and build it but am not able to compile it , Kindly help me on this :) Please find my pom.xml and PATH /usr/local/bin/grpc_cpp_plugin, sles15:~/communication/gRPC-communication # echo $PATH Still my mvn compile fails with below error . Kindly help me in this :)
When I compile am getting below error, [INFO] Compiling 1 proto file(s) to /root/communication/gRPC-communication/target/generated-sources/protobuf/grpc-cpp [ERROR] /root/communication/gRPC-communication/src/main/proto/user.proto [0:0]: grpc_cpp_plugin: program not found or is not executable |
Is |
Thanks a lot @sergei-ivanov, After giving absolute path in pom.xml for grpc_cpp_plugin and we are able generate language specific stubs using maven. |
The instructions for grpc-java mention using this plugin to generate the grpc client and/or server stub code for Java. The Java stub seems to be generated compile-custom goal and put in target/generated-sources/protobuf/grpc-java/com/seven10/gateway/io directory by default. From what I can tell from the cpptutorial, the c++ stubs are generated using the following command:
$ protoc -I ../../protos --grpc_out=. --plugin=protoc-gen-grpc="which grpc_cpp_plugin" ../../protos/route_guide.proto
Is it currently possible to do that with this plugin?
The text was updated successfully, but these errors were encountered: