Previously, we had to wait for a long compilation and packaging time for each Java application deployed to pre-release, which was very painful! Big project compilation time often near 10 minutes, life is short, ah, how many could wait ten minutes in life, so I had made some optimization efficiency team to compile, speed is very obvious, for an application test, build time reduced from 160 s to 50 s, nearly 70%, speculation the thumb up, So what did the performance team do to make the compilation speed increase so noticeable?
The first thing to say is that we use Gradle as our build tool, so we have mainly optimized Gradle commands
1. Modify gradle Build parameters
- Use – build – the cache
What is build cache? In Gradle, each Project to be compiled is called a Project, and each Project is built with a series of tasks
The input of each task can be used as the output of the next task. Not all tasks can be cached, so if the input of the task is not changed during the build process, there is no need to re-execute the task. Build 2’s Build input is taken directly from the Build Cache, so Build 1 doesn’t have to be built.
Gradle builds faster with cache than Gradle builds faster without cache. Gradle builds faster with cache than Gradle builds faster without cache
The Buiid Cache is distributed, so you can dump the Cache on the same machine, and the local machine will pull the Cache on the same machine for compilation, so you can use the Build Cache to speed up the Build process if you switch branches
Build-cache can only be used if Gradle 4.3 or above is required
- Add the –parallel argument
Parallel execution can improve compilation speed in multi-project compiled projects, but it can only be done if each project is modular and there is no coupling between each project.
- Remove the –refresh-dependencies parameter
Gradle Build has this parameter. This parameter will ignore the cache and force a re-download
2. Parallel tasks
Originally, In Jenkins, Gradle compilation tasks were executed sequentially, and the total compilation time was the sum of the execution time of each Task.
Now I’m going to make it parallel
3. Draw common codes in large projects into JAR packages
For the business side, this is also an effective way to speed up the compilation process. The large amount of code is put into jar packages, which means that it is the field code itself and does not need to be compiled during Gradle build.
Hope this article is helpful to you, remember to click on the view oh ^_^
Welcome to pay attention to the public number, common exchange learning