Gangmax Blog

IntelliJ IDEA Cannot find The Java Files Generated by Protobuf

This issue happened when the Java project has some protobuf definition file and the corresponding generated Java class could not be found in the Java classes, even the whole project could be compiled properly by “gradle clean build” command. The root cause was that, the IDE(IntelliJ IDEA) could not find the Java source code generated by the protobuf compiler althouhg the Java source code was generated already.

The solution is simple. Go to “File -> Project Structure -> Project Settings -> Modules”, in the existing default module, select “main”, click the “+ Add Content Root” link. In the pop-up file selector window, select the “/build/generated/source/proto” directory which contains where the generated Java classes are. Then the IDE can find the Java classes and the Java files depending these classes can be compiled correctly now.

Comments