【问题标题】:Maven Project Builder is invoked every time I change a source file (GWT)每次更改源文件 (GWT) 时都会调用 Maven Project Builder
【发布时间】:2011-12-19 17:11:44
【问题描述】:

最近我将我的 GWT 网络应用 (GWT 2.4.0) 转换为 maven 项目。
我正在使用 maven 2.2.1、gwt-maven plugin (2.4.0)、Eclipse Indigo (3.7) 和 m2eclipse 插件。

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

但是我有一个奇怪的行为:当我更改 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>

【问题讨论】:

    标签: eclipse gwt maven m2eclipse


    【解决方案1】:

    这完美地说明了为什么 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 build 将自动触发它们的执行。请注意,JDT 有时会决定将增量构建升级为完整构建。

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

    【讨论】:

    【解决方案2】:

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

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

    【讨论】:

    • 这是一个有趣的想法。你如何触发完整的构建?使用 pom.xml > 运行方式?
    • @MartinKersten:是的,如果我没记错的话。我已经超过 2 年没有使用它了:-P
    【解决方案3】:

    嗯,我通常不勾选:

    项目 |自动构建

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

    【讨论】:

    • Eclipse 和 Java 的强大功能在一个动作中被摧毁:-)。我喜欢一直编译所有内容,不喜欢不编译的所有内容(如 GWT)。它迫使我为一个值得的大项目编写类似于 GWT 的东西。只用了 2 周,就完美地完成了它的工作。
    • 如果您正在处理可能非常烦人的大型项目。我在日食中取消选中的第一件事
    猜你喜欢
    • 2017-12-27
    • 2015-01-28
    • 1970-01-01
    • 1970-01-01
    • 2022-01-02
    • 1970-01-01
    • 2020-02-21
    • 2011-11-23
    • 2012-08-19
    相关资源
    最近更新 更多