Skip to content
Advertisement

Ways to make maven build faster?

I have a multi module java project. Maven takes almost around 40 secs to build it. I have tried maven with multi threaded builds too by specifying -T and -C args for no of threads and cores to be used. But I haven’t seen any significant improvement in wall time of my builds.
I am using maven 3.2.3 and sometimes I need to build my project very frequently.
I know that clean goal take a lot of time but I can not omit it.
Suggestions please….

EDIT:
Note: In my case clean is not taking much time. It finishes in 1 sec. install is taking rest of the time.

Advertisement

Answer

Note: First thing is AFAIK, No other in built options available in maven apart from the all answers here.


Running maven build with Multiple threads works for me to speed up the builds. For example :

mvn clean install -T100

where -T is for specifying how many threads you want based on your hardware.

Below are the variants from wiki

Maven 3.x has the capability to perform parallel builds. The command is as follows:

  • mvn -T 4 clean install Builds with 4 threads
  • mvn -T 1C clean install 1 thread per cpu core
  • mvn -T 1.5C clean install 1.5 thread per cpu core

How Execution is evaluated(See Parallel builds in Maven 3)?

enter image description here

Each node in the graph represents a module in a multi-module build, the “levels” simply indicate the distance to the first module in the internal reactor dependency graph. Maven calculates this graph based on declared inter-module dependencies for a multi-module build. Note that the parent maven project is also a dependency, which explains why there is a single node on top of most project graphs. Dependencies outside the reactor do not influence this graph.

Finally if you want to skip test execution you can also use -DskipTests as well.

Caution : Some of your plugins may not be compatible for multithreaded builder, it may work. but it will give below warning message. you may need to see plugin documentation for multithreading support.

[WARNING] *****************************************************************                                                                                                                                 
[WARNING] * Your build is requesting parallel execution, but project      *                                                                                                                                 
[WARNING] * contains the following plugin(s) that have goals not marked   *                                                                                                                                 
[WARNING] * as @threadSafe to support parallel building.                  *                                                                                                                                 
[WARNING] * While this /may/ work fine, please look for plugin updates    *                                                                                                                                 
[WARNING] * and/or request plugins be made thread-safe.                   *                                                                                                                                 
[WARNING] * If reporting an issue, report it against the plugin in        *                                                                                                                                 
[WARNING] * question, not against maven-core                              *                                                                                                                                 
[WARNING] *****************************************************************                                                                                                                                 
[WARNING] The following plugins are not marked @threadSafe in test-project:                                                                                                                          
[WARNING] de.dentrassi.maven:rpm:0.9.2                                                                                                                                                                      
[WARNING] Enable debug to see more precisely which goals are not marked @threadSafe.                                                                                                                        
[WARNING] *****************************************************************    
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement