The first proto file(main.proto) in offline
directory
option java_package = "com.xxx.proto";
option java_outer_classname = "Service1";
option java_multiple_files = true;
message Response {
repeated Entity entity = 1;
}
message Entity {}
and here I have the second proto file(recent.proto) which is in recent
option java_package = "com.xxx.proto";
option java_outer_classname = "Service2";
option java_multiple_files = true;
message Response {
repeated Entity entity = 1;
repeated Entity.Type type =2;
}
message Entity {}
And I receive protoc: stdout: . stderr: offline/main.proto: "offline.Response.entitiy" is already defined in file "recent/recent.proto".
Want to mention Entity are different for both cases, the class name is the same
Assuming the protobuf package is the same(which in this current case is), then the messages have the same protobuf name. So it is definitely a problem.
The maven plugin may have built each file as a separate invocation to protoc, which wouldn't have noticed. The gradle plugin uses a single invocation of protoc, which has advantages and isn't something I expect to change (but others may feel differently).
If you generated these are two separate projects, then it would probably be fine. Otherwise, protobuf needs to be able to refer to the messages. That is done by name. The name is proto package + message name, potentially with nesting.
The appropriate way to do what you want is to use nested messages (or simply use different names):
message Request {
message Foo {}
}
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