News

This week The apache Ignite book becomes one of the top books of leanpub

This week The apache Ignite book becomes one of the top books of leanpub.

Wednesday

Apache maven incremental build

Apache maven is one of the popular tool for building and managing java projects. Based on the concept of a project object model (POM), Maven can manage a project's build, reporting and documentation from a central piece of information.
However when you have projects with multiple modules, it follows some issue when you compiling your project. One of them is incremental building, which means when you updates your project from the version control, you have to build the entire system by command mvn clean install. Consider the following maven project structure:
IncrementalBuild
|_ _ test-api
|_ _ test-api-impl
|_ _ test-donothing
where module test-api-impl dependent on module test-api. Whenever we will make some change on module test-api, we have to recompile and build the module test-api-impl.
If we will enter the command mvn install module test-api-impl will not get the updated version from the module test-api. You have to run command mvn clean install which will rebuild the entire project. Sometime it's time consuming and just unnecessary. You can download the project from here and check your self.
Apache maven currently doesn't support for the incremental build even on version 3.0.3.
But there is a plugin called Maven-Incremental build plugin, which can build project incrementally.
Just add the following plugin in the root pom file and you are ready for go
<plugin>
 <groupId>net.java.maven-incremental-build</groupId>
 <artifactId>incremental-build-plugin</artifactId>
 <version>1.4</version>
 <executions>
  <execution>
   <goals>
   <goal>incremental-build</goal>
   </goals>
  </execution>
 </executions>
</plugin>
Now you can run mvn install without goal clean and the project will detects the updated code and recompile modules if need.
UPD:- Note that, following page http://maven-incremental-build.java.net/site/usage.html contains incorrect groupId on example "net.java.incremental-build-plugin" which will not uploaded on central maven repository.
Resource:
1) Apache Maven Incremental Build support for WSO2 Carbon
2) Apache maven incremental plugin mojo

1 comment :

Narendra said...

can you Please tell me , how to not delete ouput directory when doing incremental build. My output directory is same for all the modules of the project. I Do not want to delete the output dir. Here is the output i am getting
DEBUG] Resolved modules : {=net.java.mavenincrementalbuild.Module@9efcfa07}
[DEBUG] Loading previous timestamps ...
[DEBUG] Using file : C:\tc\tc227\timestamp
[DEBUG] Loading previous data in C:\tc\tc227\timestamp ...
[INFO] Verifying module descriptor ...
[DEBUG] No modification on descriptor.
[INFO] Verifying parent modules...
[DEBUG] Module updated ? true
[INFO] Module updated
[DEBUG] Module updated, cleaning module
[INFO] Deleting C:\tc\tc227
[DEBUG] Saving timestamps..
[DEBUG] Saving file C:\tc\tc227\timestamp ...