Maven并行参数加快编译
一、引自stackoverflow
https://stackoverflow.com/a/54514457
mvn clean install
[INFO] Total time: 01:05 h
mvn clean install -DskipTests
[INFO] Total time: 18:35 minmvn clean install -Dmaven.test.skip -DskipTests
[INFO] Total time: 10:58 minmvn -T 1C clean install -Dmaven.test.skip -DskipTests
[INFO] Total time: 04:00 min- 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
- Dont use imports, on IntelliJ, choose > Analyze > Run inspection by name > imports , to find all imports and correct it.
- Remove all unused imports in your project > on Intellij > Analyze > Run inspection by name > unused imports
- Remove all unused code (classes, variable, field, parameter, etc..), on Intellij : Analyze > run inspection by name > unused declaration.
- Upgrade to last JAVA VERSION
- 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 newmvn 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 workmvn 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