Protoc: How to generate multiple Java source files?

After compiling a large Protobuf definition, I get a 6 MB Java source code file.

Due to its size working with this file, it is a big pain as I develop in Eclipse and Eclipse completely stops / crashes every time I open this file.

Is there a way to allow a stream to generate multiple Java source files instead of a single large file?

+6
source share
1 answer

Actually, there is. It is not documented, but you can add a line to your .proto file as follows:

 option java_multiple_files = true; 

This will put each type of top-level message from the .proto file into an independent .java file. Note that you, of course, will have to update all your code to import these classes from their new places. Note also that protoc will still generate the β€œexternal” class that it did before, without the internal classes nested inside it. The outer class is still suitable for receiving a file descriptor, top-level extension, and other non-classical objects.

All that said, if you have a .proto file that is large, I highly recommend .proto file .proto into smaller files that import each other.

+23
source

Source: https://habr.com/ru/post/976151/


All Articles