Cross-posting from stackoverflow
<https://stackoverflow.com/questions/71801138/proto3-why-setting-java-multiple-files-true-not-creating-separate-java-classe>
I have a proto definition with nested classes
syntax = "proto3";
option java_package = "com.spot.proto.v1.config";
package v1config;
message ClusterConfig {
enum LogLevel {
UNKNOWN_TYPE = 0; DEBUG = 1; INFO = 2; WARN = 3; ERROR = 4; FATAL =
5;
}
message Network {
string ip = 1;
int32 port = 2;
}
message Constants {
message SlackNotifier {
message Channel {
string name = 1;
}
string auth_token = 1;
map<string, Channel> channels = 2;
bool is_enabled = 3;
}
message Kafka {
string broker_list = 1;
}
Kafka kafka = 2;
}
message Support {
Network network = 1;
}
Support support = 1;
...
}
When I generate the java classes with option java_multiple_files = false; it
creates a single java class, ClusterConfigOuterClass.java with all the Java
classes/enums/etc generated for the top-level messages, services, and
enumerations nested inside it. This is expected.
But if I use option java_multiple_files = true; then I am seeing it is
generating two additional classes
ClusterConfig.java, ClusterConfigOrBuilder.java along with
ClusterConfigOuterClass.java. ClusteConfig.java now contains the nested
classes.
The documentation states like below:-
java_multiple_files (file option): If false, only a single .java file will
be generated for this .proto file, and all the Java classes/enums/etc.
generated for the top-level messages, services, and enumerations will be
nested inside of an outer class (see java_outer_classname). If true,
separate .java files will be generated for each of the Java
classes/enums/etc. generated for the top-level messages, services, and
enumerations, and the wrapper Java class generated for this .proto file
won't contain any nested classes/enums/etc. This is a Boolean option that
defaults to false. If not generating Java code, this option has no effect.
So should not each nested message like Kafka, Network, etc go into a
separate java file?
- Java 11
- Protoc - 3.10
--
You received this message because you are subscribed to the Google Groups
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/protobuf/6395fd3d-2577-40e3-8876-fb2b9a851281n%40googlegroups.com.