Maven has a quirk, some would say rightly bug. Without the plugin maven-incremental-plugin , the build in Maven can not be executed incrementally so as result may in some situations to reveal incorrect.
Problem Description
Consider the following project:
parent module
| --- Module-api
| --- Module-impl
The module parent module contains two sub-modules: module-api and-impl module.
The module contains a module-impl ProcessImpl class that implements the interface defined in Process module-api.
We launch the command "mvn install" on the parent project. Everything works perfectly. We modify the signature of the interface module in Process-api changes without passing on ProcessImpl-impl module.
We are launching a re-installation project on parent module with the command "mvn install".
...
[INFO] ----------------------------------------------- -------------------------
[INFO] Building module-api
[INFO] task-segment: [install]
[INFO] ----------------------------------------------- -------------------------
...
[INFO] [compiler: compile]
[INFO] Compiling 1 source file to C: \ devs \ poc-inc \ parent module \ module-api \ target \ classes
...
[INFO] [jar: jar]
[INFO] Building jar: C: \ devs \ poc-inc \ parent module \ module-api \ target \ module-api-1.0_SNAPSHOT.jar
[INFO] [install: install]
...
[INFO] ----------------------------------------------- -------------------------
[INFO] Building module-impl
[INFO] task-segment: [install]
[INFO] ----------------------------------------------- -------------------------
...
[INFO] [compiler: compile]
[INFO] Nothing to compile - all classes are up to date ...
[INFO] [jar: jar]
[INFO] [install: install]
...
[INFO]
[INFO] ----------------------------------------------- -------------------------
[INFO] Reactor Summary:
[INFO] ----------------------------------------------- -------------------------
[INFO] parent module ......................................... SUCCESS [3.828s]
[INFO] module-api ............................................ SUCCESS [2.875s]
[INFO]-impl module ........................................... SUCCESS [0.047s]
[INFO] ----------------------------------------------- -------------------------
[INFO] ----------------------------------------------- -------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ----------------------------------------------- -------------------------
The build goes smoothly and deliverables module and module-api.jar-impl.jar are installed in the Maven repository. As sources-impl module have not been edited, Maven does not recompile it, although it depends a modified module: module-api. The project status is therefore invalid in the maven repository at runtime because the implementation issue of Process by ProcessImpl throw an exception.
This problem can be solved by forcing the "clean" before each "install". The build is no longer incremental, and for modification of a single class, the rebuild is complete. In large projects using continuous integration, the total rebuild cost is too high.
Using maven-incremental-build
The plugin maven-incremental-build provides a true incremental build by not recompiling the projects that need to be.
It runs automatically when the first phase (validate) the Maven build cycle and verifies that neither the source nor the dependencies have changed since the last build. Otherwise, it forces a recompile by performing a clean project.
To activate, simply edit the parent pom to add:
... <pluginRepositories> <pluginRepository> <id> repository.dev.java.net-maven2 </ id> Java.net Repository for Maven <name> </ name> <url> http://download.java.net/maven/ 2 / </ url> <layout> default </ layout> </ pluginRepository> </ Plugin Repositories> <build> ... <plugins> ... <plugin> <groupId> org.jvnet.maven.incrementalbuild </ groupId> <artifactId> incremental-build-plugin </ artifactId> <executions> <execution> <goals> <goal> incremental-build </ goal> </ goals> </ execution> </ executions> </ plugin> </ plugins> </ build> ... With the plugin activated, if ProcessImpl is not modified in accordance with Process, the build will fail.
[INFO] ----------------------------------------------- -------------------------
[INFO] Building module-api
[INFO] task-segment: [install]
[INFO] ----------------------------------------------- -------------------------
[INFO] [incremental-build: incremental-build {execution: default}]
[INFO] Verifying module descriptor ...
[INFO] Pom descriptor modification detected.
[INFO] C: \ devs \ poc-inc \ parent module \ module-api \ target deleted
[INFO] [compiler: compile]
[INFO] Compiling 1 source file to C: \ devs \ poc-inc \ parent module \ module-api \ target \ classes
...
[INFO] [jar: jar]
[INFO] Building jar: C: \ devs \ poc-inc \ parent module \ module-api \ target \ module-api-1.0_SNAPSHOT.jar
[INFO] [install: install]
...
[INFO] ----------------------------------------------- -------------------------
[INFO] Building module-impl
[INFO] task-segment: [install]
[INFO] ----------------------------------------------- -------------------------
[INFO] [incremental-build: incremental-build {execution: default}]
[INFO] Verifying module descriptor ...
[INFO] Pom descriptor modification detected.
[INFO] C: \ devs \ poc-inc \ parent module \ module-impl \ target deleted
[INFO] [resources: resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler: compile]
[INFO] Compiling 1 source file to C: \ devs \ poc-inc \ parent module \ module-impl \ target \ classes
[INFO] ----------------------------------------------- -------------------------
[ERROR] BUILD FAILURE
[INFO] ----------------------------------------------- -------------------------
[INFO] Compilation failure
C: \ devs \ poc-inc \ parent module \ module-impl \ src \ main \ java \ en \ ippon \ vbe \ ProcessImpl.java: [3.7] is not abstract and fr.ippon.vbe.ProcessImpl Does not override abstract method method (int, int, boolean) in fr.ippon.vbe.Process
With the plugin maven-incremental-build , the project is necessarily in a valid state in performing cleans only when necessary.
Links:
Site plugin: http://maven-incremental-build.dev.java.net/
Discussion on the incremental build in Maven: http://markmail.org/message/kdij7s7jlm2crlip



Pingback: Boon's Blog »Blog Archive» Maven Incremental Builds