Eclipse下Maven增量编译

Maven Incremental Compilation under Eclipse

我最近将一个大的(丑陋的)遗留项目转换为 Maven。这是一个非常庞大的项目(约 270 万行代码,以及 java、jsp、js 甚至 VBS 脚本的完美组合)并且结构不合理。一切都位于单个 Maven 工件下(因此是单个 Eclipse 项目)。

即使结构如此糟糕,它过去也更容易从 Eclipse 中管理(即使有点慢),但现在,由于它是 Mavenized,对源代码所做的每一次更改都会触发几乎完全重建代码库(2.7M LoC 大约需要 10 分钟才能完成),每天都无法使用。

我发现了以下与 maven-compiler-plugin 相关的错误报告,无法进行增量编译:https://issues.apache.org/jira/browse/MCOMPILER-205,我非常有信心这是我们性能问题的根源。

你有什么解决办法吗?您知道没有受该问题影响的 maven-compiler-plugin 版本吗?或者 Eclipse 中的设置可以提供帮助?还有其他想法吗?

谢谢

Disable automatic build 是您唯一的选择。当您对工件感兴趣时就构建。

你没说什么goals you are calling maven with。如果您不 运行 所有使用 -DskipTests 的测试(或者甚至不使用 -Dmaven.test.skip=true 编译它们),或者如果不愿意跳过那些引入配置文件到 运行 只是必要的测试。

既然你说这是一个遗留项目,我怀疑将项目结构更改为 multi-module Maven 项目超出了范围。然后,您可以尝试使用 parallel builds(使用 -T 4(4 个线程)或 -T 2C(每个内核 2 个线程)来加速。

Eclipse 中的增量编译器(ecj,由 JDT 使用)完全覆盖了命令行 Maven 构建使用的编译器。任何 maven-compiler-plugin 或 javac 问题都应该被视为无关紧要而被丢弃。我希望 m2e/Maven 对单个项目工作区没有重大影响,尽管它很大。显然,因为您看到了相反的行为,所以显然是某些东西减慢了 Maven 构建器的速度。

由于您使用 jsp 和 js 文件,我猜这是一个 war 项目。如果您使用的是 Eclipse Java EE 发行版,您可以尝试的一件事是禁用 m2e-wtp 集成,看看它是否有任何不同。转到首选项 > Maven > Java EE 集成并取消选中启用 Java EE 配置。

如果这没有帮助(或不适用于您的设置),您可以尝试的另一件事是在增量构建期间禁用 Maven 资源处理。在您的 pom.xml 中,尝试添加:

    <profiles>
  <profile>
    <id>m2e</id>
    <!-- This profile is only activated when building in Eclipse with m2e -->
    <activation>
      <property>
        <name>m2e.version</name>
      </property>
    </activation>
    <build>
      <pluginManagement>
        <plugins>
          <!--This plugin's configuration is used to store Eclipse m2e settings 
            only. It has no influence on the Maven build itself. -->
          <plugin>
            <groupId>org.eclipse.m2e</groupId>
            <artifactId>lifecycle-mapping</artifactId>
            <version>1.0.0</version>
            <configuration>
              <lifecycleMappingMetadata>
                <pluginExecutions>
                  <pluginExecution>
                    <pluginExecutionFilter>
                      <groupId>
                        org.apache.maven.plugins
                      </groupId>
                      <artifactId>
                        maven-resources-plugin
                      </artifactId>
                      <versionRange>
                        [1.0,)
                      </versionRange>
                      <goals>
                        <goal>resources</goal>
                        <goal>testResources</goal>
                      </goals>
                    </pluginExecutionFilter>
                    <action>
                      <ignore></ignore>
                    </action>
                  </pluginExecution>
                </pluginExecutions>
              </lifecycleMappingMetadata>
            </configuration>
          </plugin>
        </plugins>
      </pluginManagement>
    </build>
  </profile>
</profiles>

它有可能破坏其他东西,但至少这应该有助于确定资源处理是否是这里的罪魁祸首。

还有什么需要深入分析的,建议大家开票https://bugs.eclipse.org/bugs/enter_bug.cgi?product=M2E