我想使用Gradle下载依赖项及其源文件,并将它们全部放在一个目录中。我在下面找到了这个答案,该答案告诉我如何针对依赖项本身进行操作,但我也想获取源文件。我怎么做?
我知道Eclipse插件可以抓取源文件,但是我不知道它在何处放置它们。
How can I use Gradle to just download JARs?
最佳答案
这有效
apply plugin: 'java'
repositories { ... }
dependencies {
compile 'foo:bar:1.0'
runtime 'foo:baz:1.0'
}
task download {
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)
.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 configurations.runtime
from sourceArtifacts
into "${buildDir}/download"
}
}
}
关于java - 如何使用Gradle下载依赖项及其源文件并将它们全部放置在一个目录中?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39975780/