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.

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?
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With