IntelliJ IDEA takes a long time when refreshing a Gradle project

Farzad picture Farzad · Jul 5, 2016 · Viewed 8k times · Source

I have a very large project, with many sub-projects configured in Gradle. When I do a clean build from the command line, it takes about 10 minutes, but after that, building the whole project is very fast.

My problem is when importing the project into IntelliJ Community Edition. When importing for the first time, it takes about 10 minutes, but after that, whenever I do a refresh on the project, it still takes the same amount of time. I see the background task being executed: I see messages being displayed very quickly, and then it's stock at Gradle: Build, and I have no idea what it's doing!

I tried to increase log level, and I see a DEBUG message saying that: .project.GradleProjectResolver - Gradle data obtained in 311943 ms, which I think is the reason it takes a lot of time, but as I said, I have no idea what it's doing that needs this amount of time

BTW, I'm using the gradle wrapper (not sure if it makes a difference)

Any help is appreciated, Thanks in advance

Answer

Stijn Van Bael picture Stijn Van Bael · Mar 13, 2017

I was experiencing a similar problem with Gradle 3.4.1 and IDEA 2016.3.5. A refresh of a sizeable project was taking about 30 minutes. I've hooked up YourKit profiler to the Gradle daemon to investigate what it was doing. I noticed it spent a lot of time in java.net.Inet6AddressImpl.lookupAllHostAddr. When I googled that issue, I quickly found this solution: http://justthesam.com/2016/10/fixing-java-net-inet6addressimpl-lookupallhostaddr-slowdown/

It appears to be an issue with Java processes on Mac OSX on a network that does not support IPv6, resulting in timeouts on IPv6 lookups. To apply this fix, enter hostname in a terminal window to lookup your hostname. Then add the hostname to /etc/hosts.

127.0.0.1   localhost Your-Hostname-Here
::1         localhost Your-Hostname-Here

Leave localhost in there to make sure you don't break anything else. Kudos to Sam for finding this fix.

Note that you may experience long refreshes for a lot of different reasons. But hooking up a profiler on the Gradle daemon should give you more insight into what is going on.