Search code examples
eclipsemavenm2eclipse

Maven Incremental Compilation under Eclipse


I've recently converted a big (and ugly) legacy project to Maven. It is a really really huge project (~2.7M lines of code, and a nice mix of java, jsp, js, and even VBS scripts) and is not well structured. Everything is located under a single Maven artifact (and thus a single Eclipse project).

Even with that bad structure, it used to be less or more manageable from Eclipse (even if a bit slow), but now, since it is Mavenized, every single change made to source code triggers an almost full rebuild of the code base (and 2.7M LoC take something like 10 minutes to finish), which is really unusable on a daily basis.

I've found the following bug report related to maven-compiler-plugin, unable to have an incremental compilation: https://issues.apache.org/jira/browse/MCOMPILER-205, and I'm quite confident that this is the root of our performance issues.

Have you any workaround? Do you know of a maven-compiler-plugin version not impacted with that issue? Or a setting in Eclipse which could help? Any other idea?

Thanks


Solution

  • The incremental compiler in Eclipse (ecj, used by the JDT) totally overrides the compiler used by command line Maven builds. Any maven-compiler-plugin or javac issue should be discarded as irrelevant. I would expect m2e/Maven to have no significant impact on a single project workspace, as big as it is. Obviously since you're seeing the opposite behavior, something is apparently slowing down the Maven builder.

    Since you use jsp and js files, my guess this is a war project. If you're using the Eclipse Java EE distribution, one thing you can try is to disable the m2e-wtp integration, see if it makes any difference. Go to Preferences > Maven > Java EE Integration and uncheck Enable Java EE Configuration.

    If that doesn't help (or doesn't apply to your set up), another thing you could try would be to disable Maven resource processing during incremental builds. In your pom.xml, try adding:

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

    There's a chance it might break something else, but at least that should help determine whether resource processing is the culprit here.

    Anything else will require a deeper analysis, I suggest you open a ticket to https://bugs.eclipse.org/bugs/enter_bug.cgi?product=M2E