IntelliJ IDEA takes a long time when refreshing a Gradle project
Asked Answered
B

2

12

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

Bracelet answered 5/7, 2016 at 18:4 Comment(1)
Might be the same issue as this: intellij-support.jetbrains.com/hc/en-us/community/posts/…Carryingon
C
13

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.

Carryingon answered 13/3, 2017 at 14:28 Comment(1)
I tried this in Intellj Idea 17.3, doesn't work. But according to VisualVM, there is RMI TCP connection thread in Gradle Daemon, which waits for something.Tourneur
A
2

For future readers:

I learned a couple of things during this journey.

Number 1. ORDER MATTERS on your list of potential repos. If you put "https://repo1.mycompany.com:443/artifactory/Our-Releases/" first, it will try there first, and probably fail, then go to jcenter land. This was my primary issue.

If you have a multi module project...try to centralize in the (root) build.gradle. Aka, remove any "repository" declarations in the (non root) build.gradle files.

Typically, do NOT include "mavenLocal". See link below.

Typically, pick jcenter or mavenCentral, but since jcenter is a superset of mavenCentral, you don't need both. see SOF answer link below.

repositories {

    // ORDER MATTERS HERE.  See : https://mcmap.net/q/235612/-difference-among-mavencentral-jcenter-and-mavenlocal/50726436#50726436
    
    //  As a general advice, you should avoid adding mavenLocal() as a repository.   https://docs.gradle.org/current/userguide/declaring_repositories.html#sec:case-for-maven-local 
    //mavenLocal()
    jcenter()
    //jcenter is a superset of mavenCentral() so we do not specify mavenCentral here
    maven { url "https://repo1.mycompany.com:443/artifactory/Our-Releases/" }
    maven { url "https://repo1.mycompany.com:443/artifactory/Our-Snapshots/" }


}

For my multi module gradle setup, I have the above nested inside of

subprojects { 
}

If you have a monolith :( then you won't nest under subprojects.

Now, if I put the above in "subprojects"...I had to put a few of them in the (root) build.gradle

// repositories that apply to ONLY the root project.
repositories {
    jcenter()

}

Or you can put everything in "allprojects" if you want root and module repositories to be the same.

Just try to consolidate as best you can.

FEBRUARY / MARCH 2022 UPDATE

jcenter() is now deprecated.

use

mavenCentral()

instead of jcenter()

see : JCenter deprecation; impact on Gradle and Android

Argentous answered 17/10, 2020 at 10:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.