Friday, February 10, 2012

Maven 3: How to Speed-up Build Process?

I was working on one of the project and one of my worry was that 'mvn clean install' was taking too long. I tried the following options which resulted in faster build. Here are my learnings:

  • Maven Commands: Maven 3 has come up with some advanced commands known as reactors. One of theeir experimental features is Parallel Builds. This build-mode analyzes your project's dependency graph and schedules modules that can be built in parallel according to the dependency graph of your project. The commands are as follows:

    mvn -T 4 clean install         # Builds with 4 threads
    mvn -T 2C clean install        # Runs 2 thread per cpu core
    

    Second command works better for multicore processors.
  • Using mvnsh: mvnsh(Maven Shell) allows developers to execute maven goals/phases in a pre-loaded shell environment. It is a CLI interface for Apache Maven that enabled faster turn-around. Maven Shell does not come with Maven 3 build. You can download it separately from Sonatype site.

    Following are the excellent article which provides details on mvnsh:

    http://ericmiles.wordpress.com/2010/03/23/intro-to-maven-shell
    http://ericmiles.wordpress.com/2010/03/26/maven-shell-features

    How to use mvnsh?

    After downloading the mvnsh, you can use it in following manner:

    Run mvnsh.bat from /bin directory. This will take you to maven shell environment with mvnsh(/):bin> shell option.

    Now traverse to your project's POM.xml directory using:

    cd <YOUR_POM_XML_DIR>

    This will take you to mvnsh(/):<YOUR_POM_XML_DIR>> shell in mvnsh environment and now you can run your normal mvn commands.

No comments: