每次更改源文件 (GWT) 时都会调用 Maven Project Builder

发布于 2024-12-22 08:29:59 字数 5300 浏览 2 评论 0原文

最近,我将 GWT Web 应用程序 (GWT 2.4.0) 转换为 Maven 项目。
我正在使用 maven 2.2.1、gwt-maven 插件 (2.4.0)、Eclipse Indigo (3.7)和 m2eclipse 插件。

依赖关系和一般配置似乎都很好,因为网络应用程序编译没有任何问题,并且也可以在生产模式下工作。
这同样适用于托管模式。

但是我有一个奇怪的行为:当我更改 Java/GWT 源文件中的一行时,将调用 Maven Project Builder,并且此步骤需要非常长的时间(大约 10 秒),并且 eclipse 有时会变得无法使用这段时间。

这是 m2eclipse 的正常行为吗?

如果是,有什么方法可以加快速度吗?

注意:我必须为 m2eclipse 配置生命周期插件。这是 pom 文件的重要部分:

<build>
        <!-- Generate compiled stuff in the folder used for developing mode -->
        <outputDirectory>${webappDirectory}/WEB-INF/classes</outputDirectory>

        <plugins>

            <!-- GWT Maven Plugin -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>gwt-maven-plugin</artifactId>
                <version>2.4.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>test</goal>
                        </goals>
                    </execution>
                </executions>
                <!-- Plugin configuration. There are many available options, see gwt-maven-plugin 
                    documentation at codehaus.org -->
                <configuration>
                    <runTarget>index.html</runTarget>
                    <hostedWebapp>${webappDirectory}</hostedWebapp>
                    <i18nMessagesBundle>com.gmi.nordborglab.testapp.client.Messages</i18nMessagesBundle>
                </configuration>
            </plugin>

            <!-- Copy static web files before executing gwt:run -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.1.1</version>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>exploded</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <webappDirectory>${webappDirectory}</webappDirectory>
                </configuration>
            </plugin>
        </plugins>

        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.eclipse.m2e</groupId>
                    <artifactId>lifecycle-mapping</artifactId>
                    <version>1.0.0</version>
                    <configuration>
                        <lifecycleMappingMetadata>
                            <pluginExecutions>
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>org.codehaus.mojo</groupId>
                                        <artifactId>gwt-maven-plugin</artifactId>
                                        <versionRange>[2.4.0,)</versionRange>
                                        <goals>
                                            <goal>resources</goal>
                                            <goal>compile</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <execute />
                                    </action>
                                </pluginExecution>
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>org.apache.maven.plugins</groupId>
                                        <artifactId>maven-war-plugin</artifactId>
                                        <versionRange>[2.1.1,)</versionRange>
                                        <goals>
                                            <goal>exploded</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <execute />
                                    </action>
                                </pluginExecution>

                            </pluginExecutions>
                        </lifecycleMappingMetadata>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>

    </build>

Recently I converted my GWT web-app (GWT 2.4.0) to a maven project.
I am using maven 2.2.1, gwt-maven plugin (2.4.0), Eclipse Indigo (3.7) and the m2eclipse plugin.

The dependencies and general configuration seem to be fine as the web-app compiles without any problems and also works in production mode.
The same applies to hosted mode.

However I have a strange behavior: When I change a single line in a Java/GWT source file, the Maven Project Builder is invoked and this steps takes painfully long (around 10 secs) and eclipse sometimes becomes unusable during this time.

Is this a normal behavior of m2eclipse?

And if it is, is there any way to speed it up?

Note: I had to configure the life cycle plugin for m2eclipse. Here is the important section of the pom file:

<build>
        <!-- Generate compiled stuff in the folder used for developing mode -->
        <outputDirectory>${webappDirectory}/WEB-INF/classes</outputDirectory>

        <plugins>

            <!-- GWT Maven Plugin -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>gwt-maven-plugin</artifactId>
                <version>2.4.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>test</goal>
                        </goals>
                    </execution>
                </executions>
                <!-- Plugin configuration. There are many available options, see gwt-maven-plugin 
                    documentation at codehaus.org -->
                <configuration>
                    <runTarget>index.html</runTarget>
                    <hostedWebapp>${webappDirectory}</hostedWebapp>
                    <i18nMessagesBundle>com.gmi.nordborglab.testapp.client.Messages</i18nMessagesBundle>
                </configuration>
            </plugin>

            <!-- Copy static web files before executing gwt:run -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.1.1</version>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>exploded</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <webappDirectory>${webappDirectory}</webappDirectory>
                </configuration>
            </plugin>
        </plugins>

        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.eclipse.m2e</groupId>
                    <artifactId>lifecycle-mapping</artifactId>
                    <version>1.0.0</version>
                    <configuration>
                        <lifecycleMappingMetadata>
                            <pluginExecutions>
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>org.codehaus.mojo</groupId>
                                        <artifactId>gwt-maven-plugin</artifactId>
                                        <versionRange>[2.4.0,)</versionRange>
                                        <goals>
                                            <goal>resources</goal>
                                            <goal>compile</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <execute />
                                    </action>
                                </pluginExecution>
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>org.apache.maven.plugins</groupId>
                                        <artifactId>maven-war-plugin</artifactId>
                                        <versionRange>[2.1.1,)</versionRange>
                                        <goals>
                                            <goal>exploded</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <execute />
                                    </action>
                                </pluginExecution>

                            </pluginExecutions>
                        </lifecycleMappingMetadata>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>

    </build>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

手长情犹 2024-12-29 08:29:59

这完美地说明了为什么 m2e 默认情况下不允许任何“未知”插件在增量构建上运行( http:// /wiki.eclipse.org/M2E_plugin_execution_not_covered#Background )。大多数 Maven 插件不适合增量构建,并且在调用它们时都会进行完整的构建(作为奖励,您可能会遇到类加载器泄漏)。

在插件管理部分中,您指定应执行 gwt:resources、gwt:compile 和 war:exploded。默认情况下,它们在增量构建上执行,这意味着每次资源更改时都会执行。由于这些目标/插件没有针对增量构建进行优化,因此它们需要一段时间才能完成。

如果您想加快速度,您可以通过使用告诉 m2e 仅在完整构建(即项目清理后)上执行它们,

<execute>
  <runOnIncremental>false</runOnIncremental>
</execute>

然后,手动执行 eclipse clean 构建将自动触发它们的执行。请注意,JDT 有时会决定将增量构建升级为完整构建。

我相信(但可能是错误的),如果您使用 Google Eclipse 插件,您可以完全忽略 gwt:resources 和 gwt:compile (通过将替换为)。

This perfectly illustrates why m2e doesn't let any "unknown" plugins to run on incremental build by default ( http://wiki.eclipse.org/M2E_plugin_execution_not_covered#Background ). Most maven plugins aren't fit for incremental building and do a complete build whenever they're invoked (and as a bonus, you might get classloader leakages).

In your plugin management section, you specified that gwt:resources, gwt:compile and war:exploded should be executed. By default, they're executed on incremental builds, that means on EVERY resource change. Since these goals/plugins aren't optimized for an incremental build, they take a while to complete.

If you want to speed things up, you can tell m2e to execute them only on Full builds (i.e. after a project clean) by using

<execute>
  <runOnIncremental>false</runOnIncremental>
</execute>

Then, manually doing an eclipse clean build will automatically trigger their execution. Be aware that JDT sometimes decides to promote incremental builds to full ones.

I believe (but may be wrong) that, if you were using the Google Eclipse Plugin, you could ignore gwt:resources and gwt:compile altogether (by replacing <execute> with <ignore>).

放手` 2024-12-29 08:29:59

Maven 构建的原因很可能是启用的 Maven Project Builder(项目属性 > 构建器)。

您可以禁用它——只要您选择了Java Builder——Eclipse 将继续编译已编辑的文件。

The reason for the Maven build is more than likely an enabled Maven Project Builder (Project properties > Builders).

You can disable it and -- as long as you have the Java Builder selected -- Eclipse will continue to compile edited files.

清欢 2024-12-29 08:29:59

好吧,我通常取消选中:

项目|自动构建

我只是讨厌它一直在编译。

Well, I usually uncheck :

Project | Build Automatically

I just hate it getting compiling all the time.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文