apache_maven

The obvious things to do first in no particular order

  • Use a better build server, CPU power is cheap today,
  • Throw more memory, as Maven run in a JVM the more you have the better it may behave, you may want also to increased the perm gen space,
  • Use the latest  version of JVM!
  • Switch as many plugins as possible as long as there are not needed in the main build loop: Use profile to modularize your build and trigger some additional build/reporting plugins when needed. You want your build to be fast to provide fast feedback to your developers.
  • Optimize your test cases, some may take longer than other, use @BeforeClass or Lazy initialization to cache some heavy to create objects,
  • Tune the garbage collector according to your build behavior, number of CPU core:  use parallel garbage collector for example,
  • Carefully review your dependencies as the less Apache Maven has to load while building the faster it will get.
    • Are they all needed?
    • No duplicates dependencies?
    • Do you miss some <exclusions>? are all these transitive dependencies to your 3rd party needed?
    • No dependencies cycles? check the order in reactor. A developer should understand, and not be surprised by  the order of the modules calculated by Maven (as long as you have layers in your software, you expect some modules to be build before some others) .
  • Review ALL logs files
    • The one created by Maven to avoid any warnings and
    • All your application logs (do you log too much data during the build?)

Speed up Apache Maven builds by building modules in parallel in reactor

The first beta of Maven 3 saw the introduction of a parallel build feature which leverages a configurable number of cores on a multi-core machine and is especially suited for large multi-module projects.

This feature require Apache Maven 3, even if it is not final, I highly recommend you to try to use it. We have it since the version 3.0 Alpha 2 in use without any apparent drawbacks (we have some old custom Maven plugin that still require 2.2 through but luckily there are not in the main build loop)

Full documentation can be found on the Maven wiki: Parallel builds in Maven 3

Try to build your software using 4 threads, we saw an increase of 1.5 minutes on a 7 minutes build.

mvn -T 4 clean install

 

Speed up Apache Maven builds by running test cases concurrently in reactor

 

Caveats

Some test cases may not like to run in parallel, (remember concurrency is not an easy subject in software development) Potential problems are:

  • Resources that are shared
    • Files,
    • Database access,
    • Mutable instance variables.
  • You have a lot of integration tests that may conflicts
  • You check in teardown() some post conditions that may conflict if run in parallel.

Surefire permit to run tests in parallel either at

  • Method level
  • Class level
  • both

In JUnit 4.7 the values are classes/methods/both to run in separate threads, as controlled by threadCount.

This is particularly useful for slow tests that can have high concurrency, or to quickly and roughly assess the independence and thread safety of your tests and code.

<plugin>
 <groupId>org.apache.maven.plugins</groupId>
 <artifactId>maven-surefire-plugin</artifactId>
 <version>2.5</version>
 <configuration>
  <parallel>methods</parallel>
 </configuration>
</plugin>

 

Read more at JUnit site, maven-surefire-plugin site and surefire mojo parameters

comments powered by Disqus

You might like also

Fetching artifact programmatically through REST/API in Nexus 3.x
There is so many case where it is desirable to pull down artifact from Sonatype Nexus using REST API, unfortunately Nexus 3.x Rest API are still under development... Some use cases in Nexus 2.x: You have a script that uses REST call to pull down the LATEST maven artifacts every night from Nexus and deploys them. You make extensive use of the REST API in all your puppet modules You use the Atlassian Puppet module for Nexus for creating repository, …
664 Days ago
git-branch-renamer-maven-plugin
When working with many feature/release/bugix/hotfix branches, it is a bad idea to start changing the pom version as this will create merge conflicts using pull request. this plugin allow you to keep in ALL branches the same pom version for all your projects, for example MASTER-SNAPSHOT the version will be derived from branch name automagically :-) You may want to read more first these 2 short articles Update Maven pom version on GIT checkout in TeamCity maven-release-plugin with GIT git-branch-renamer-maven-plugin …
676 Days ago
Review: Getting Started with Apache Maven by Russell Gold
Some time ago I was asked if I would like to write a review about one of the new video courses from Packt Publishing. It was "Getting Started with Apache Maven" http://bit.ly/1fycmpP by Russell Gold and since I have been using Maven for some years now (since 2007) and did publish some articles myself, I thought it would be nice to help them promote Apache Maven. The course is organized in eight chapters, forty videos with a length between two …
1863 Days ago
Update Maven pom version on GIT checkout in TeamCity
Here is a solution to the following problems Deriving Maven artifact version from GIT branch, Update pom version on GIT checkout automatically, Add the ability to use Pull request with Apache Maven. You have a workflow requirement that require you to have the artifact version of a module externally defined from the current branch in GIT. For example You want to start working on a new feature branch “feature-memory-improvement”, so you branch from master a new branch named feature/feature-memory-improvement Having …
1868 Days ago
Easily Compress Web Application Resources with EhCache
Resources such as JavaScript and CSS files can be compressed before being sent to the browser, improving network efficiencies and application load time in certain case. If you are not using Apache with mod_deflate or nginx in front of your web application, you may need to implement resources compression yourself…. Wait! don’t start writing your own filter to compress files like CSS, html, txt, javascript it is way more difficult than you think to properly handle http response headers and …
2350 Days ago
Tomcat 7 and Apache Maven
Here is 3 different way to control the lifetime a local Tomcat 7 container using Apache Maven. A typical scenario would be to start a servlet container prior to running integration tests (Selenium, SAHI or using any other framework you can think of ) With the following examples, you will be able to start an instance of Tomcat 7 running your web application in the pre-integration-test phase and stop the instance in the post-integration-test phase. You can also decide to …
2350 Days ago
Apache Maven copy local file to a remote server server using SSH
I will show you in an Apache Maven configuration file how to copy files to server each time the package phase is executed. Solution with Ant SCP task This snippet of code is a ready to use code that make use of Apache Ant task scp, Just put this snippet of code in your Maven module where the assembly is executed or anywhere else to push all tar.gz files to a server just run a maven mvn package, you can …
2538 Days ago
Apache M2Eclipse: Get rid of Duplicate resources when opening resources and types
In this small post, I’ll show you how to remove duplicated resources in the Open Resource view of Eclipse Eclipse – M2Eclipse – Subversive …
2544 Days ago
Apache Maven 3 Cookbook
&160; First a big thanks to Packt Publishing for having sent me this book to review! I did enjoy going through this book, while I did not learn a lot of new stuff (I am using Apache Maven daily since 2006!), I found it to be concise and would recommend it anytime to any of my colleagues. But let’s go through my review of this cookbook of over 50 recipes towards optimal Java Software Engineering with Maven 3: Apache Maven
2686 Days ago
Apache Maven 3 Cookbook Review
Thanks to Packt Publishing for having sent me this book to review. I will publish a review in the next coming days Grasp the fundamentals and extend Apache Maven 3 to meet your needs Implement engineering practices in your application development process with Apache Maven Collaboration techniques for Agile teams with Apache Maven Use Apache Maven with Java, Enterprise Frameworks, and various other cutting-edge technologies Develop for Google Web Toolkit, Google App Engine, and Android Platforms using Apache Maven You …
2732 Days ago