由buildbuf生成代码引起的Eclipse构建循环(与Maven Project Builder相关) [英] Eclipse build loop caused by protobuf generated code (related to Maven Project Builder)

查看:425
本文介绍了由buildbuf生成代码引起的Eclipse构建循环(与Maven Project Builder相关)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一种依赖于 Maven Java 客户端/服务器项目://code.google.com/p/protobuf/rel =nofollow noreferrer>协议缓冲区(protobuf),用于在客户端和服务器之间发送RPC。我将Java for Java EE 中的 Eclipse用作主IDE。因为我在我的项目中使用Maven,所以我使用了Eclipse的 m2eclipse 插件。我在Eclipse中配置我的项目以使用Maven Nature。

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".

基本上,如果Eclipse配置为自动构建(默认为项目菜单 - >自动构建),则我正在运行INFINITE BUILD LOOPS。每当Eclipse旋转构建时,构建将进入无限循环,通常会导致我的所有计算机的CPU资源被Eclipse消耗,最终由于内存溢出,错误弹出窗口将出现在IDE中。正在发生的事情是,通过Eclipse构建,由Maven持续构建的所有来自 .proto 文件的Java代码。一旦将原始文件生成并编译成目录(在我的情况下, target / generated-sources ),则会立即重复构建原始文件。即使我点击停止按钮,构建也将再次脱离。我可以真正地停止无限的构建循环的唯一方法是禁用自动构建。

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.

从查看网络上的链接(请参阅此 SOF post ,也列在下面),一个解决方法是禁用 Maven项目构建器我的Eclipse项目。要这样做,我将不得不打开Eclipse项目设置 - > Builders - >取消选择Maven Project Builder。现在,无限的构建循环不会发生,似乎是因为m2eclipse的构建器是罪魁祸首。但是,我现在从这个构建器中失去了很多有用的功能。也就是说,我无法通过m2eclipse利用资源过滤的自动资源处理优势。请注意,使用Maven Nature的项目包含资源目录( src / main / resources src / test / resources )在Java构建路径上,因为期望Maven项目构建器将它们添加到类路径中。所以,我遇到的Maven项目构建器遇到的一个问题是我在测试中看不到类路径中的资源文件。我必须首先运行一个手动的maven构建来访问资源(但是一旦我刷新项目,我将无法再找到这些类路径资源)。或者,我可以改变我的项目的Java构建路径,但这违反了Maven Nature的默认设置,除了依赖protobuf之外的所有Eclipse Java项目中都有效。

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.

有没有人有任何想法如何解决这个问题? Eclipse平台似乎太成熟,无法让这个问题继续坐下。我可以随时提交一个将收集灰尘的Eclipse错误,但也许这不是Eclipse错误,而是我身边的错误配置。非常感谢你的帮助。

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.

  • 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

推荐答案

阅读附件 GitHub Issue 看起来,在protobuf-maven中设置 cleanOutputFolder 插件做的伎俩以下是使用插件的示例XML(版本无关):

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>

这意味着Eclipse不会遇到无限的构建循环,因为Maven Project Builder不必不断重新编译同一个protobuf生成的文件夹,它位于 / target / generated-sources 中。同时,没有启用 cleanOutputFolder 不能完全禁用该项目从原始文件输出和基于这些文件生成新的源代码;只要使用干净的目标运行Maven构建命令(例如 mvn clean install ),那么生成源目录仍将被重新生成,因为目标目录已被删除。

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.

这篇关于由buildbuf生成代码引起的Eclipse构建循环(与Maven Project Builder相关)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆