Maven Incremental Compilation under Eclipse - 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

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

Disable automatic build is the only option you have. Just build when you are interested in the artifacts.
You did not say what goals you are calling maven with. Maybe it would already be enough if you do not run all tests using -DskipTests (or even not compile them by using -Dmaven.test.skip=true), or if not willing to skip those introduce profiles to run just the necessary tests.
Since you are telling it's a legacy project I suspect that changing the project structure into a multi-module maven project is out of scope. You can then try if you can speed up using parallel builds (using -T 4 (4 threads) or -T 2C (2 threads per core).

Related

How to automatically generate lexer+parser with ANTLR4 and Maven?

I'am new to ANTLR4, and it seems that there is no Eclipse-Plug-In for v4. So it would nice to build automatically the Java sources from the .g4 grammars. I have a simple, empty Maven-project with src/main/java, src/test/java. Where to place the .g4 files? How can I automatically build the grammars with Maven?
My own POM-test failed:
<repository>
<id>mvn-public</id>
<name>MVNRepository</name>
<url>http://mvnrepository.com</url>
</repository>
...
<build>
<plugins>
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>4.0.0</version>
<executions>
<execution>
<goals>
<goal>antlr</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Eclipse says:
Failure to find org.antlr:antlr4-maven-plugin:pom:4.0.0 in http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of
central has elapsed or updates are forced
I created the following Gist with a pom.xml designed solely for supporting automatic code generation from ANTLR 4 grammars during an Eclipse build. It includes the necessary lifecycle information for m2e to know that the code generation is necessary, and explicitly adds the code generation folder using the build-helper-maven-plugin since Eclipse seemed to have some trouble locating it otherwise.
In this configuration, grammar files (*.g4) are placed alongside the other Java source files. The Maven plugin will automatically add the proper package ... statement to the generated files, so you shouldn't include a #header{package ...} line in the grammar itself.
https://gist.github.com/sharwell/4979017
Check out this Antlr4 plugin for Eclipse
https://github.com/jknack/antlr4ide

How to set eclipse project specific validation preferences with m2e

When invoking importing maven projects into eclipse from git using "Import Maven Projects" the m2e plugins to seems to generate a new .project and .classpath and some other files even though those files are checked in.
To get around this problem I would like to not check in any eclipse specific files, but there are customizations made to each project file such as custom save actions, or changes to the validation to ignore specific things, or changes to the javascript configuration for a dynamic web project that need to be preserved, so either those files need to checked or those settings need to be generated by m2e.
Any way to use m2e to configure the eclipse project validators?
We had a similar problem in the past. We solved it by
don't checkin eclipse specific files (svn ignore, git ignore, ...)
Use Workspace Mechanic plugin to keep eclipse settings the same accross development machines / developers.
The other answer has suggested the solution with eclipse. But if you are flexible with using a different IDE, I suggest using Netbeans with git. I tested both IDEs and finally found out I could save time in different cases using Netbeans! No such problems as mentioned above.
I made m2e-codestyle-maven-plugin for another purpose but it should serve what you need as well (in my case I wanted to set the default settings to have all validations turned on from my coding-standards project.
The key thing you have to do is fork a copy of my coding-standards project and add/change the appropriate setting in org.eclipse.wst.validation.prefs namely
vals/org.eclipse.wst.xml.core.xml/global=FF03
To disable the validations for XML for example. You can have it activated only on m2e by using profiles as shown here
https://github.com/trajano/jee/blob/master/jee-domain-api/pom.xml#L24
<profile>
<id>m2e</id>
<activation>
<property>
<name>m2e.version</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>net.trajano.mojo</groupId>
<artifactId>m2e-codestyle-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>configure</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>net.trajano</groupId>
<artifactId>coding-standards</artifactId>
<version>${coding-standards.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</profile>

Datanucleus Maven Plugin

How to fix this issue with Eclipse maven project:
Plugin execution not covered by lifecycle configuration:
org.datanucleus:maven-datanucleus-plugin:3.1.0-m3:enhance (execution:
default, phase: compile) pom.xml /DatanucleusJPA line 218 Maven
Project Build Lifecycle Mapping Problem
Is this fixable with the Eclipse M2 Eclipse plugin?
Preface:
I suppose this is nothing Datanucleus specific at all, but a feature of Eclipse Maven plugin instead. All that you have tried, apparently works if running on command line (Linux) or Cygwin[1] (Windows). The issue here is that Eclipse m2 plugin needs some more info for working properly and make its tricks and that is where the question lies and that's why you asked.
Possible solutions:
Like pointed already in comments, every detail can be found from the given link to [2] M2E site, and the essentials appear in one answer to one question [3] about the same issue. I take this snippet from one of it's answers:
<action>
<execute />
</action>
These lines should be fine, added inside the last element inside your <plugin-executions> element on your project pom.xml. I am not magician, I can only use Google, so without code / pom content given in question I suggest you have followed Datanucleus own instructions [4] and had there something like:
<plugins>
<plugin>
<groupId>org.datanucleus</groupId>
<artifactId>maven-datanucleus-plugin</artifactId>
<version>3.1.0-m3</version>
<configuration>
<log4jConfiguration>${basedir}/log4j.properties</log4jConfiguration>
<verbose>true</verbose>
</configuration>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
..and well, there it is only <executions>, but place it there.
Sidenote:
Funny though, while using Google for searching what would be the issue, that question was already voted up by me and there my answer of choice was different, looking like this:
<build>
<pluginManagement>
<plugins>
<plugin> ... </plugin>
<plugin> ... </plugin>
....
</plugins>
</pluginManagement>
</build>
..the trick being to add that <pluginmanagement> part to the xml. I just remember to have taken a fresh copy of my projects from SVN and after that I did not use that trick anymore. Maybe that problem is old or someone in my company committed that trick. Anyways, worth of testing, too.
Answer to the question:
Not, not directly with plugin, but tweak the pom.xml file.
My sources:
[1] http://cygwin.com - running Linux commands at Windows.
[2] http://wiki.eclipse.org/M2E_plugin_execution_not_covered - suggested in comments
[3] How to solve "Plugin execution not covered by lifecycle configuration" for Spring Data Maven Builds - includes lines of quotation

How to compile only changed parts of gwt modules?

We decided to use gwt modules in our application about 1 week ago. We use gwt-maven-eclipse trio and we already configured phases and goals. Also we are doing context deploying to decrease development and testing time.
BUT;
When we package or tomcat:deploy our application, gwt modules are re-compiling(including unchanged ones).
<set-property name="user.agent" value="gecko1_8"></set-property>
<extend-property name="locale" values="en_UK"></extend-property>
I already set these properties up here to speed up compiling time but this is not what i want exactly...
I also configured maven lifecycle mapping in eclipse to fire gwt:compile process-resources resources:testResources when any resources change. But it blocks eclipse and that was not helpful about compiling time either.
This is gwt-maven-plugin configuration in pom.xml
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.3.0</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<!--
Plugin configuration. There are many available options, see
gwt-maven-plugin documentation at codehaus.org
-->
<configuration>
<runTarget>A.jsp</runTarget>
<runTarget>B.jsp</runTarget>
<hostedWebapp>${webappDirectory}</hostedWebapp>
</configuration>
</plugin>
Any idea to help me?
gwt-maven-plugin tries (hard) to avoid recompiling modules when the code hasn't changed, but even that takes a bit of time (still less than re-compiling the module; and unfortunately if it detects the module needs to be recompiled, it adds up to the GWT compile time).
If you know you don't need gwt:compile, you can pass -Dgwt.compiler.skip=true to your Maven build to skip the goal and keep "running" your previously compiled code. Similarly, if you know you need gwt:compile, you can pass -Dgwt.compiler.force=true to bypass the "up-to-date check".

Replace Maven Site Plugin with GWT Compile Plugin

I have successfully set up a few projects which use Maven to automatically deploy the Maven-generated site to the gh-pages branch of their git repository. GitHub then serves these files at a public URL on a personal subdomain. I'm looking to utilize this functionality to serve a rich client-side only GWT application.
I have modified my pom.xml to compile the GWT application to the target/site/ directory. The two main goals I am still attempting to achieve are:
How do I prevent the standard Maven site plugin from running during the site phase?
What is required so gwt:compile executes during the site phase?
A goal can be bound to a phase by specifying a new execution for the plugin. I'm assuming you've got some custom stuff you need to make most of this work correctly, so I'm just going to focus on what should work to bind a plugin goal to a particular phase.
<plugin>
<artifactId>gwt-maven-plugin</artifactId>
...
<executions>
<execution>
<id>gwt-site</id>
<phase>site</phase><!-- phase to bind to -->
<goals>
<goal>compile</goal><!-- goal to run in that phase -->
</goals>
<configuration>
<!-- Your magic configuration stuff goes here -->
</configuration>
</execution>
<!-- Possible other executions might be defined here -->
</executions>
</plugin>
Preventing the default maven site from being run is more interesting, as it is a phase, with a variety of goals bound to it. The standard site:site goal can be prevented from running in the site phase by explicitly specifying an execution with no goals. This may vary slightly from maven 2 to 3, so I'm going to be a little general here. Take a look at your build logs to see what is currently specified in terms of execution id, group/artifact id to correct possible oversights in my example:
<plugin>
<artifactId>maven-site-plugin</artifactId>
...
<executions>
<execution>
<phase>site</phase>
<goals></goals><!-- This is empty to indicate that no goals should be run in this phase -->
</execution>
</executions>
</plugin>