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â
did you find a bypass? I encounter the same problem on an artefact (Central Repository: org/json4s/json4s-jackson_2.13/4.0.7)
Bypass to what?
That IntelliJ is showing decompiled class file instead of sources?
That library is written in Scala.
So even if IntelliJ knows and has the source jar, the sources cannot be displayed if you donât have the Scala plugin installed, as the IDE does not know what a Scala file is.
Install the Scala plugin and the Scala source file will be displayed instead.