Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Maven support incremental builds?

Tags:

java

maven

How does one use Maven to support incremental builds? Is there a guide somewhere? (top Google results are disappointing)

like image 459
ripper234 Avatar asked Jan 18 '12 22:01

ripper234


People also ask

Does maven do incremental builds?

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.

What is incremental build Java?

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.

What incremental builds?

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.

How do incremental builds work?

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.


2 Answers

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

like image 153
robert Avatar answered Sep 20 '22 12:09

robert


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++.)

like image 20
Donal Fellows Avatar answered Sep 21 '22 12:09

Donal Fellows