Unable to get IntelliJ to recognize proto compiled Java class files

Siddhartha picture Siddhartha · May 5, 2015 · Viewed 7.4k times · Source

We have a build.xml in our project, but IntelliJ is unable to import from it. I get a:

Cannot import anything from <path_to>/build.xml file.

On Eclipse I can do a:

File -> Import -> General -> Existing Projects into workspace.

and chose top-level folder. I did the same in IJ. The project imported and indexed fine, I can do a search for any class. However, it does not recognize protobuf compiled class files. I installed the proto plugin, so it syntax highlights my .proto files, but still doesn't realize that there's a compiled class output that it needs to refer to. Do I need to do something special to get it to recognize those files?

Answer

michele b picture michele b · Jan 19, 2016

since this is pretty much the only place I could find an exact description for the issue I was facing with Idea, I'm replying even if it's an old question.

It turns out that if the .java file that's generated by the protocol buffers compiler is larger than 2.5MB (default setting), Idea ignores it altogether. Even if there is a .class file, even if compile/make succeed, even if you build your project just fine with Maven.

To fix that, simply edit your idea.properties file (it's inside the bin folder in your Idea installation folder), and either comment out this setting, or set it to something larger than your generated .java file (in my case, I set it to 15000, as my generated file is currently about 8MB in size):

#---------------------------------------------------------------------
# Maximum file size (kilobytes) IDE should provide code assistance for.
# The larger file is the slower its editor works and higher overall system memory requirements are
# if code assistance is enabled. Remove this property or set to very large number if you need
# code assistance for any files available regardless their size.
#---------------------------------------------------------------------
idea.max.intellisense.filesize=2500

Note: at least on Linux, where the default update policy seems to be "overwrite the old Idea folder with what you just downloaded", this change must be applied after every update/upgrade.