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

Closed
amarcionek opened this Issue May 15, 2017 · 2 comments

Comments

2 participants
@amarcionek
Copy link

amarcionek commented May 15, 2017

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?

@sergei-ivanov

This comment has been minimized.

Copy link
Member

sergei-ivanov commented May 18, 2017

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, grpc_cpp_plugin needs to be built/downloaded separately and made available in the $PATH (or an absolute path needs to be specified in the POM).

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,
Sergei

@amarcionek

This comment has been minimized.

Copy link

amarcionek commented May 19, 2017

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

@amarcionek amarcionek closed this May 19, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment