Do you think that running gradle task for generating full idea project and waiting so long that it takes forever to complete? Now there's a solution for that! Running gradle idea task will finish faster than waiting your pg
service build finished!
Disclaimer: This solution result will vary depending on your current system configuration, hardware specification, current memory usage, whether Meltdown and Spectre mitigation patch enabled, and radioactive/quantum event on your machine luck.
Gradle idea task process is scale linearly with total submodule within your project. With our current repo that ever-increasing, gradle idea task process will be slowed down as well. Memory consumption is also bigger (compared to codebase one year earlier). If your JVM setting is too low (or too big), this will make your gradle task slow (because of JVM GC being fired too often and eventually crash because OOM event) or your system freeze (because of high memory pressure and aggresive swap activity).
Using correct JVM parameter and freeing your memory is your only viable choice for now. Always close your background task prior to executing gradle idea task, and watch memory usage. All steps will explained in the section below.
gradle.properties
. Edit the line that begin with org.gradle.jvmargs=
with correct value. This line below works on our company laptop (other system will need to adjust these options):
org.gradle.jvmargs=-Xms1440m -Xmx14400m -XX:ReservedCodeCacheSize=256m -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=384m -XX:+UseConcMarkSweepGC -XX:ConcGCThreads=8 -XX:ParallelGCThreads=8 -XX:+CMSParallelRemarkEnabled -XX:+UseCMSInitiatingOccupancyOnly -XX:+ScavengeBeforeFullGC -XX:+CMSScavengeBeforeRemark
./gradlew --parallel --max-workers=4 idea
to limit worker threads to 4 (this options is to balance heap generation rate and garbage collection sweep rate). This process should be completed before reaching 12 minute mark. If the task is still running after 12 minute, report it to @ardhinata and he will try to investigate what's the problem causing it.
gradle.properties
with initial value to prevent being commited to repo. You can reset this by using git checkout HEAD -- gradle.properties
.
After your gradle idea task done, your IntelliJ IDEA will freezing on the first load. You can kill it and try to load it again, or wait until all indexed cache cleared and refreshed by IDEA. If your IDEA is still freezes after this steps, I recommend to update your IntelliJ IDEA to current latest version, increase IDEA JVM heap memory to 8GiB, and using Concurrent Mark Sweep GC.
http://jvmmemory.com
https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/cms.html
https://www.oracle.com/technetwork/articles/java/vmoptions-jsp-140102.html
Personal experiences