jhamm
jhamm

Reputation: 25032

Why is my protoc not generating gprc service stubs?

I am pulling grpc into my spring-boot-project. I pulled in this dependency:

<dependency>
   <groupId>io.github.lognet</groupId>
   <artifactId>grpc-spring-boot-starter</artifactId>      
   <version>4.5.8</version>
</dependency>

Here is my plugins section:

<extensions>
    <extension>
        <groupId>kr.motd.maven</groupId>
        <artifactId>os-maven-plugin</artifactId>
        <version>1.6.2</version>
    </extension>
</extensions>
<plugins>
    <plugin>
        <groupId>org.xolstice.maven.plugins</groupId>
        <artifactId>protobuf-maven-plugin</artifactId>
        <version>0.6.1</version>
        <configuration>
            <protocArtifact>com.google.protobuf:protoc:3.17.2:exe:${os.detected.classifier}</protocArtifact>
            <pluginId>grpc-java</pluginId>
            <pluginArtifact>io.grpc:protoc-gen-grpc-java:1.39.0:exe:${os.detected.classifier}</pluginArtifact>
        </configuration>
        <executions>
            <execution>
                <goals>
                    <goal>compile</goal>
                    <goal>compile-custom</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
</plugins>

Here is my protoc file:

syntax = "proto3";

option java_package = "com.aeonai.proto";

service OrderService {
  rpc ExecuteOrder(OrderRequest) returns (OrderResponse) {};
}

message OrderRequest {
  string email = 1;
  string product = 2;
  int32 amount = 3;
}

message OrderResponse {
  string info = 1;
}

When I run mvn clean install I get all of the java classes, other than the OrderService. What else needs to happen to create the service?

Upvotes: 3

Views: 1377

Answers (1)

Terry
Terry

Reputation: 159

I took a crack at this and I was able to generate the OrderService stub classes. Here's what I did:

  1. Create a fresh Spring Boot app at start.spring.io
  2. Update pom.xml with the exact XML snippets from the question.
  3. Add the proto definition to src/main/proto/demo.proto
  4. Run ./mvnw clean install

What I get in under target/classes/com/aeonai/proto are these files:

Demo$OrderRequest$1.class
Demo$OrderRequest$Builder.class
Demo$OrderRequest.class
Demo$OrderRequestOrBuilder.class
Demo$OrderResponse$1.class
Demo$OrderResponse$Builder.class
Demo$OrderResponse.class
Demo$OrderResponseOrBuilder.class
Demo.class
OrderServiceGrpc$1.class
OrderServiceGrpc$2.class
OrderServiceGrpc$3.class
OrderServiceGrpc$MethodHandlers.class
OrderServiceGrpc$OrderServiceBaseDescriptorSupplier.class
OrderServiceGrpc$OrderServiceBlockingStub.class
OrderServiceGrpc$OrderServiceFileDescriptorSupplier.class
OrderServiceGrpc$OrderServiceFutureStub.class
OrderServiceGrpc$OrderServiceImplBase.class
OrderServiceGrpc$OrderServiceMethodDescriptorSupplier.class
OrderServiceGrpc$OrderServiceStub.class
OrderServiceGrpc.class

The OrderService classes are there, but note that they are not inner classes of the "Demo" class. Without knowing your exact project setup I'm not sure how to help further, but you could try the steps I took and see if you then get the service classes. And if you do, see what the delta is with your actual project setup.

Upvotes: 1

Related Questions