# How do I force gradle to download dependency sources

**URL:** <https://discuss.gradle.org/t/how-do-i-force-gradle-to-download-dependency-sources/34726>\
**Category:** Help/Discuss\
**Created:** [January 29, 2020, 6:56am UTC](https://discuss.gradle.org/t/how-do-i-force-gradle-to-download-dependency-sources/34726 "2020-01-29T06:56:57Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Lance](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lance/32/787_2.png) [@Lance](https://discuss.gradle.org/u/Lance)\
**Post date:** [January 29, 2020, 8:07am UTC](https://discuss.gradle.org/t/how-do-i-force-gradle-to-download-dependency-sources/34726/2 "2020-01-29T08:07:18Z")

</div>

If you’re using eclipse or intellij plugins there’s support for doing this. Eg

```gradle
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'eclipse'

eclipse {
    classpath {
       downloadSources=true
       downloadJavadoc = true
    }
}
idea {
    module {
        downloadJavadoc = true
        downloadSources = true
    }
}

```

Or you can use an [ArtifactResolutionQuery](https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.query.ArtifactResolutionQuery.html) to do it programmatically

```gradle
task copyJavadocsAndSources {
    inputs.files configurations.runtime
    outputs.dir "${buildDir}/download"
    doLast {
        def componentIds = configurations.runtime.incoming.resolutionResult.allDependencies.collect { it.selected.id }
        ArtifactResolutionResult result = dependencies.createArtifactResolutionQuery()
            .forComponents(componentIds)
            .withArtifacts(JvmLibrary, SourcesArtifact, JavadocArtifact)
            .execute()
        def sourceArtifacts = []
        result.resolvedComponents.each { ComponentArtifactsResult component ->
            Set<ArtifactResult> sources = component.getArtifacts(SourcesArtifact)
            println "Found ${sources.size()} sources for ${component.id}"
            sources.each { ArtifactResult ar ->
                if (ar instanceof ResolvedArtifactResult) {
                    sourceArtifacts << ar.file
                }
            }
        }

        copy {            
            from sourceArtifacts
            into "${buildDir}/download"
        }
    }
} 

```

See [https://stackoverflow.com/questions/39975780/how-can-i-use-gradle-to-download-dependencies-and-their-source-files-and-place-t/39981143#39981143](https://stackoverflow.com/questions/39975780/how-can-i-use-gradle-to-download-dependencies-and-their-source-files-and-place-t/39981143#39981143)

---

_[View the full topic](https://discuss.gradle.org/t/how-do-i-force-gradle-to-download-dependency-sources/34726)._
