I forked https://github.com/cgrushko/proto_library on my local machine, imported the workspace into intellij and built. I then added the following java main class:
package src;
import demo.PersonOuterClass;
public class Main {
public static void main(String argv[]) {
byte[] ba = PersonOuterClass.Person.newBuilder().setEmail("dwwd").build().toByteArray();
for (byte b : ba) {
System.out.println(b);
}
}
}
and the following build rule
java_binary(
name = "Main",
main_class = "src.Main",
srcs = ["Main.java"],
deps = [":person_java_proto"]
)
The program builds and runs properly, but in intellij toByteArray() is red and intellij says that it can't resolve the method.
I suspect the issue is that generated Person extends com.google.protobuf.GeneratedMessageV3 but intellij doesn't know about GeneratedMessageV3 and that it extends a class, AbstractMessageLite, that defines the toByteArray method.
Anyone know how to fix either the bazel build target(s) or intellij so that toByteArray is resolved by the ide?
Thanks,
Tom.
src/
bazel-blx/external/com_google_protobuf_java/java/core/src/main/java
3. Open project structure -> Modules and remove the package prefix from the second folder from step 2
Then the sources for protobuf lib resolve, but every time I sync, I have to repeat step 3.
Is there a way to avoid having the bazel plugin add a package prefix to the source folder for the
protobuf source folder?
Thanks,
Tom.