Title says it all. How do I force gradle to download dependency sources
If youâre using eclipse or intellij plugins thereâs support for doing this. Eg
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 to do it programmatically
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"
}
}
}
I tried both. It doesnât work . IntelliJ still decompiles it when I try to look at code of library.
I can only guess that you didnât actually run the tasks after adding the snippets.
Eg gradlew eclipse
or gradlew copyJavadocsAndSources
Did it now. Still the same thing.
I just realised you are using intellij. Try gradle cleanIdea idea
Task âcleanIdeaâ not found.
Did you
apply plugin: 'idea'
Yes. It doesnât work.
Can you tell a bit more about the project. Is it a multi-module build? Where are you applying the idea plugin? Are you only doing it for the root project? or are you applying it for all the java projects?
Itâs not multi module project. Iâm applying it right after plugins have been declared e.g
plugins {
id âsomethingâ
// you know
}
apply plugin: âideaâ