eclipse - Eclipse下Maven增量编译

标签 eclipse maven m2eclipse

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

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

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

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

谢谢

最佳答案

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

关于eclipse - Eclipse下Maven增量编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35055942/

相关文章:

java - 为什么这个 .equals() 不起作用?

java - Spotify docker maven 构建多个镜像

java - 在 tomcat 上运行 Maven Struts2 应用程序

eclipse - Eclipse 和 Maven 多模块项目的依赖性问题

java - 无法创建自定义 BOM。项目构建失败,无法解析导入 POM : Could not find artifact

android - 错误 : "DENSITY_XHIGH cannot be resolved or is not a field"

java - Eclipse远程开发

Java JUnit Eclipse 错误 : Type mismatch cannot convert from void to double

scala - Scala 测试数据放在哪里

maven - 使用 Ant 任务更改 Maven 属性