Attaching Gradle sources in IntelliJ IDEA

John Jai picture John Jai · Oct 30, 2014 · Viewed 11.4k times · Source

Once after I create a Gradle project in IntelliJ using the default gradle wrapper and create directories option I see the project structure gets created with build.gradle file.

IntelliJ tips me to "You can configure Gradle wrapper to use distribution with sources. It will provide IDE with Gradle API/DSL documentation" - but I am not able to attach the sources even after clicking "Ok, apply suggestion". The Gradle project is getting refreshed but the sources are not attached.

We are using a Nexus repository.

Answer

Kinmarui picture Kinmarui · Oct 24, 2017

To improve on @anon58192932 answer you can use only gradleVersion and distributionType fields of Wrapper task and don't need to manually create distributionUrl which is more error prone since you could change gradle version in one place, but not in the other.

task wrapper(type: Wrapper) {
    gradleVersion = '4.2'
    distributionType = Wrapper.DistributionType.ALL
}

@edit gradle 4.8+ will produce error for above. Use instead

wrapper {
    gradleVersion = '4.2'
    distributionType = Wrapper.DistributionType.ALL
}