我想使用 Gradle 下载依赖项及其源文件,并将它们全部放在一个目录中。我在下面找到了这个答案,它告诉我如何为依赖项本身做这件事,但我也想获取源文件。我怎么做?
我知道 Eclipse 插件可以抓取源文件,但我不知道它把它们放在哪里。
这有效
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"
}
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2914 次 |
最近记录: |