Top 10 New Features in Maven 3
Maven 3.0 was just released and the Java build tool has come a long way since version 2 was released almost six years back. Maven 2 had reached a stage where it was difficult to extend and its code was difficult to understand. In version 3.0 many of the Maven internals have been revamped to overcome all the issues associated with Maven 2. In this article, I run down the top 10 features in Maven 3.
1. Backward Compatibility
Maven founder and Sonatype CTO Jason van Zyl says that "Maven 3 is built for the user," which is evident from the fact that Maven 3.0 is a drop-in replacement for Maven 2.x. The Maven 3 developers have worked hard to make sure that the transition from Maven 2.x to Maven 3.0 is smooth. Maven 3.0 will issue warnings if a duplicate dependency or plugin declarations or plugin version numbers are not specified. Maven 3.0 highly recommends that you fix these problems in your POM as future versions of Maven 3 might not support building malformed projects. I tried porting my multiple-module project to Maven 3 and it worked like a charm. I also got the aforementioned warnings but I didn't face any problems or get any build errors. Maven 3.0 is a viable option for Maven 2.x.
2. Performance Improvement
The most important feature for which I would migrate to Maven 3 is its speed. Through better disk I/O, network I/O, CPU utilization, and memory consumption, Maven 3 is tuned to perform 50-400% faster than Maven 2.x. Faster Maven builds lead to higher developer productivity. I ran my project against Maven 3 and it took less than 2 minutes when previously it had taken close to 3 minutes. This was without making any changes such as running parallel builds (which I will discuss shortly). I just downloaded Maven 3 and built my project against it. Maven 3's speed alone made migrating from Maven 2.x worth it for me.
3. Automatic Parent Versioning
In Maven 2, you have to specify the parent version in the sub-modules, which is a maintenance problem when you start development on a new version. Maven 3.1 will eliminate the need to specify the parent version in sub modules.
4. Parallel Builds
Maven 3 has also introduced a new feature called parallel builds, which analyzes your project dependency graph and enables you to build schedule modules in parallel. To run a project with parallel build, you use this command:
mvn -T 2 clean install mvn -T 2C clean install
The first command says build this Maven project with two threads, and the second command says build this project with two threads per core. With parallel builds, you can achieve performance improvements of 20-50%. However, parallel builds are an experimental feature that can change in the future, so it is not wise to use them in production.
5. Better Error and Integrity Reporting
Maven 3 has improved error reporting, and it provides you with a link to the Maven wiki page where you will get a full description of the error and the possible causes (see Figure 1). For example, I tried running one of my sub modules without a parent version and it gave me an error. Note that you will not be required to write parent POM versions in sub modules in Maven 3.1.