How to download dependency sources for Gradle project in IDEA?

I've got problems with the following configuration:

idea {
    module {
        // if you hate browsing Javadoc
        downloadJavadoc = false

        // and love reading sources :)
        downloadSources = true
    }
}

repositories {
    mavenLocal()
    mavenCentral()
}

When removed mavenLocal() sources were downloaded and attached.


For Kotlin DSL:

plugins {
    idea
}

idea {
    module {
        isDownloadJavadoc = true
        isDownloadSources = true
    }
}

I noticed that when you already have a jar downloaded then its sources and not downloading after changing build.gradle.

Removing .m2 from my home directory and calling gradle helped.


If you need to keep mavenLocal() repository due to dependencies on snapshot jars (or some other reasons), you can get the source jar using maven.

mvn dependency:get -Dartifact=GROUP_ID:ARTIFACT_ID:VERSION:jar:sources

For example,

mvn dependency:get -Dartifact=org.springframework:spring-core:5.1.2.RELEASE:jar:sources