Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse build loop caused by protobuf generated code (related to Maven Project Builder)

Development Environment

I am working on a Maven Java client/server project that relies on Protocol Buffers (protobuf) for sending RPCs between the clients and server. I use Eclipse for Java EE as my primary IDE. Since I use Maven in my project, I am using the m2eclipse plugin for Eclipse. I configure my project in Eclipse to use the "Maven Nature".

The Problem

Basically, with the workspace setup described above, I am running into INFINITE BUILD LOOPS if Eclipse is configured to Build Automatically (which is the default: Project Menu --> Build Automatically). Whenever Eclipse spins off a build, the build will enter an infinite loop, often resulting in all my computer's CPU resources being consumed by Eclipse and eventually an error popup will appear in the IDE due to a memory overflow. What is happening is that all the generated Java code from the .proto files are continuously being built by Maven via the Eclipse build. Once the proto files are generated and compiled into a directory (in my case, target/generated-sources), the build of the proto files is immediately repeated. Even if I was to click on the stop button, the build would spin off again. The only way I can really stop the infinite build loop is to disable Build Automatically.

From looking through links on the web (see this SOF post, also listed below), one workaround was to disable the Maven Project Builder on my Eclipse project. To do so, I would have to open up the Eclipse project settings --> Builders --> deselect Maven Project Builder. Now, the infinite build loop will not happen, seemingly because it was m2eclipse's builder that was the culprit. However, I now lose a lot of useful functionality from this builder. Namely, I am not able to take advantage of automatic resource processing through m2eclipse, such as resource filtering. Note that projects using the Maven Nature have resource directories (src/main/resources and src/test/resources) excluded on the Java Build Path because of the expectation that the Maven Project Builder adds them to the classpath. So, one issue I run into with the Maven Project Builder disabled is that I cannot read resource files from the classpath in my tests. I would have to first run a manual maven build to get access to the resources (but once I refresh the project, I won't be able to find these classpath resources anymore). Or, I could change my project's Java Build Path, but that goes against the Maven Nature's defaults that work for me in all Eclipse Java projects besides ones relying on protobuf.

So, that all being said...

Does anyone have any idea how I can work around this problem? The Eclipse platform seems too mature to have this problem continue to sit around. I could always file an Eclipse bug that will collect dust, but perhaps it is not an Eclipse bug but rather an incorrect configuration on my side. Thank you so much in advance for the help.

Related Links

  • SOF post about this issue: Eclipse loops endlessly: Invoking 'Maven Project Builder'
  • Open Github issue for the maven-protobuf-plugin: https://github.com/igor-petruk/protobuf-maven-plugin/issues/16
like image 729
ecbrodie Avatar asked Apr 30 '14 22:04

ecbrodie


1 Answers

After reading the attached GitHub Issue more carefully, it appeared that setting the cleanOutputFolder configuration in the protobuf-maven-plugin did the trick. Here is an example XML of using the plugin (version is irrelevant):

<plugin>
    <groupId>com.github.igor-petruk.protobuf</groupId>
    <artifactId>protobuf-maven-plugin</artifactId>
    <version>0.6.3</version>
    <configuration>
        <cleanOutputFolder>false</cleanOutputFolder>
    </configuration>
</plugin>

This means that Eclipse will not run into an infinite build loop because the Maven Project Builder will not have to keep recompiling the same protobuf generated folder, which is in /target/generated-sources. Meanwhile, not having cleanOutputFolder enabled doesn't completely disable the project from picking up proto file outputs and generating new sources based on those files; as long as a Maven build command is run with the clean goal (such as mvn clean install), then the generated-sources directory will still be regenerated since the target directory had already been deleted.

like image 58
ecbrodie Avatar answered Oct 05 '22 08:10

ecbrodie