How does one use Maven to support incremental builds? Is there a guide somewhere? (top Google results are disappointing)
Currently (3.0. 4) Apache Maven doesn't support incremental builds very well. Because of that fact, most people use mvn clean compile instead of mvn compile for example. This is pretty time consuming and can be improved a lot.
This is what the incremental compiler does: it analyzes the dependencies between classes, and only recompiles a class when it has changed, or one of the classes it depends on has changed.
Incremental builds are builds that are optimized so that targets that have output files that are up-to-date with respect to their corresponding input files are not executed.
The incremental build model is a method of software development where the product is designed, implemented and tested incrementally (a little more is added each time) until the product is finished. It involves both development and maintenance.
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 ...
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++.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With