Maven Tips to optimize build timings
Few Maven Tips and tricks to make Maven builds fast and faster and efficiently.
This can help to reduce the build timings drastically and optimize your build timings
- Run compilation parallel
mvn -T 2 clean compile
#Above will trigger 2 threads
mvn -T 1C clean install
#Above will trigger 1 thread per CPU, if you have 2 CPU core then 2 threads will be spawned.
#You can even give number in fraction (1.5, 2.5 etc).
Note - > Maven takes care of dependency and calculate if 2 modules are dependent and will compile the first one before other. Still parallel builds feature is going through lot of extensive testing and subjected to use.
I have faced dependency problem in some cases and had to revert back to normal build. This will not work with maven-release-plugin.
But it works 90% of time.
- Skip the unit test
-DskipTests
-Dmaven.test.skip=true
-Darguments="-DskipTests"
The first one will skip the test, latter one will not even compile the tests which will save the time and make maven build fast.
Last one will be use when you use maven release plugin and you want to skip the test during release prepare and perform.
- Running the tests in separate thread with extra memory
-Dmaven.junit.fork=true
and
-Dmaven.compile.fork=true
and
-Dmaven.testng.fork=true
Give extra memory to thread
-Dmaven.junit.jvmargs=-Xmx512m
- Skip the JavaDoc when you are running daily regular build.
- Don't look remote Maven
-o Option will make your build offline, This means your build will no longer look for any artifacts from remote maven server and will use from local .m2.
Comments
Post a Comment