Does Maven support incremental builds?
How does one use Maven to support incremental builds? Is there a guide somewhere? (top Google results are disappointing)
Solution 1:
I can't quite figure out the dynamic that drives the Maven community but it isn't one that's friendly to having fine-grained control over your build-process.
Anyhow, after digging around I found an answer that worked for me here: http://www.codesenior.com/en/tutorial/Java-Maven-Compile-Only-Changed-Files
Note that setting the value to false
confused me at first, but an explanation is given here: https://stackoverflow.com/a/19653164/409638
Reproduced here for convenience:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<useIncrementalCompilation>false</useIncrementalCompilation>
</configuration>
</plugin>
It's the useIncrementalCompilation
set to false
that is key here.
I can confirm that when I run my build I have gone from:
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 114 source files to /home/vagrant/workspace/splat/target/classes
to
[INFO] Compiling 1 source file to /home/vagrant/workspace/splat/target/classes
which has shaved a few seconds of my incremental build. Now all I've got to do is figure out how to disable all the other unnecessary cruft that's slowing down my edit/evaluate cycles ...
Solution 2:
Maven builds incrementally by default, but it turns out that the compiler plugin (i.e., the core of javac) is so fast that building fresh every time is not a bottleneck with sane codebase sizes, not by comparison with constructing large assemblies or running large test suites. (Java, like most languages, is much faster to compile than C++.)
Solution 3:
You can use the maven-incremental build plugin, if your project has hundreds of modules. It saves lot of time.