How can I speed up my maven2 build?

There are some possibilities to optimize some of the build tasks. For example the 'clean' task can be optimized from minutes to just milliseconds using simple trick - rename 'target' folder instead of delete.

To get details how to do it refer to Speed up Maven build.


I don't know what version of Maven you are using, I assume 2, but I will give what I use for Maven 1.x to speed up and make things build a tiny bit quicker.

These will fork the junit tests into a new process (also helps when you use environment variables in tests etc and gives the tests a little more memory.

-Dmaven.junit.fork=true
-Dmaven.junit.jvmargs=-Xmx512m

This forks the compilation which might speed things up for you

-Dmaven.compile.fork=true

I hope this can help a little, try it out.

Also refer to get more speed with your maven2 build.


If you are using Maven3 ($ mvn -version), you can also follow this guide. In my case, the results are:

Normal execution:

$ mvn clean install 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 03:05 min
[INFO] Finished at: 2015-07-15T11:47:02+02:00
[INFO] Final Memory: 88M/384M

With Parallel Processing (4 threads):

$ mvn -T 4 clean install
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 02:22 min (Wall Clock)
[INFO] Finished at: 2015-07-15T11:50:57+02:00
[INFO] Final Memory: 80M/533M

Parallel Processing (2 threads per core)

$ mvn -T 2C clean install

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 02:12 min (Wall Clock)
[INFO] Finished at: 2015-07-15T12:00:29+02:00
[INFO] Final Memory: 87M/519M
[INFO] ------------------------------------------------------------------------

As we can see, the difference it's almost a minute, near 20-30% of speed improvement.

Tags:

Maven 2