Automatic translation

Archives

October 2008
The My Me J V S D
"September November "
A 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31

Contributors

A true incremental build in Maven

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

  • Arnaud Heritier http://aheritier.net

    Hello,

    I heard about your plugin recently. I did not know him and I confess that I am clean formatted / install when needed. The problem is real and I wonder if Maven 3 will not be able to respond more clean and mostly native. It would be good to talk about our mailing lists to see what the community thinks today. The thread is mentioned in 2007 and everyone already forget (if only someone did read it because there has not been a lot of developers who responded). A mail on the dev list would not be bad for my taste

    A + +

    Arnaud

    PS: No I will not push the subject because I personally do not have time for cons I am ready to support you if necessary :-)

  • http://ouelcum.wordpress.com/ Lawrence T.

    Thank you for the pointer to the plugin :) Bizarreness that I was a bit annoyed.

  • Benoit Guerout

    Commmetn are you?

    I see that our illustrious colleague maitient his plugin.

    Note for 1 year nothing has changed at Maven to resolve this problem.

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