Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grpc cannot resolve symbol GreeterGrpc

Tags:

java

grpc

I am following the link https://github.com/grpc/grpc-java/tree/master/examples/src/main/java/io/grpc/examples/helloworld here to try to get grpc working.

enter image description here

this is the final folder structure.

And my HelloWorldServer.java is the same as https://github.com/grpc/grpc-java/blob/master/examples/src/main/java/io/grpc/examples/helloworld/HelloWorldServer.java, except the package name.

but Intellij tells that it cannot resolve symbol GreeterGrpc.

Could someone help me out of here please?

like image 682
Alex Avatar asked Jun 05 '17 06:06

Alex


2 Answers

Notice that GreeterGrpc.java is under generated-sources, but IntelliJ doesn't know it's a source file.

I see that target/generated-sources/protobuf/java is marked as generated sources root, but target/generated-sources/protobuf/grpc-java is not. Normally IntelliJ picks this up from the configuration in pom.xml. Maybe you don't have something correctly configured there. You could try to reimport the Maven module by right-click on pom.xml, and select Maven and then Reimport. The icon of grpc-java should change to blue with a gear, like java at the same directory level.

If that doesn't work, then you could mark grpc-java as a generated source root manually: right-click on it, select Mark Directory as and then Generated Sources Root.

like image 70
janos Avatar answered Sep 20 '22 20:09

janos


The Protobuf plugin assumes Protobuf files (*.proto) are organized in the same way as Java source files, in sourceSets. The Protobuf files of a sourceSet are compiled in a single protoc run, and the generated files are added to the input of the Java compilation run of that sourceSet ().

sourceSets {
    main {
        java {
            srcDirs 'build/generated/source/proto/main/grpc'
            srcDirs 'build/generated/source/proto/main/java'
        }
    }
}

Thanks to @https://medium.com/@DivyaJaisawal/generate-java-code-from-proto-file-using-gradle-1fb9fe64e046

like image 42
abdul rashid Avatar answered Sep 20 '22 20:09

abdul rashid