Maven并行参数加快编译

一、引自stackoverflow

https://stackoverflow.com/a/54514457

  1. mvn clean install [INFO] Total time: 01:05 h
  1. mvn clean install -DskipTests [INFO] Total time: 18:35 min
  2. mvn clean install -Dmaven.test.skip -DskipTests [INFO] Total time: 10:58 min
  3. mvn -T 1C clean install -Dmaven.test.skip -DskipTests [INFO] Total time: 04:00 min
  4. We can also skip the javadoc to be generated as Archmed commented by adding -Dmaven.javadoc.skip=true mvn -T 1C clean install -Dmaven.test.skip -DskipTests -Dmaven.javadoc.skip=true
  5. Dont use imports, on IntelliJ, choose > Analyze > Run inspection by name > imports , to find all imports and correct it.
  6. Remove all unused imports in your project > on Intellij > Analyze > Run inspection by name > unused imports
  7. Remove all unused code (classes, variable, field, parameter, etc..), on Intellij : Analyze > run inspection by name > unused declaration.
  8. Upgrade to last JAVA VERSION
  9. I have found that the task mvn clean, is taking 2 minutes to clean the TARGET folder before building. I did create a new task called quickclean, and i am using it instead of clean, this way mvn -T 1C quickclean install -Dmaven.test.skip -DskipTests . This new task quickclean is only renaming the build folder from TARGET to TARGET-yyyy-MM-dd-HH-mm(what is VERY FAST). So now, every time you make a new mvn quickclean install..., you have a folder with the time of the build. The inconvient, it’s that this may take a lot of space on the hard disk, so you have to clean all this directories sometimes. So for that i have created another task called: trashclean, to put all this folder to trash. I am running this tasks maybe on time per week. or month, depending on my work mvn trashclean.

二、引自Wiki

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

1)mvn -T 4 clean install

Builds with 4 threads

2)mvn -T 1C clean install

1 thread per cpu core

3)mvn -T 1.5C clean install

1.5 thread per cpu core

# 参考

  1. https://stackoverflow.com/questions/32368976/ways-to-make-maven-build-faster
  2. https://cwiki.apache.org/confluence/display/MAVEN/Parallel+builds+in+Maven+3

评论