使用工件名称解压 gradle 依赖项
Unzip gradle dependencies using artifact name
我正在寻找一种方法来将特定配置的项目依赖项提取到工作区文件夹中。由于可能存在多个依赖项,我想将每个工件提取到一个具有工件名称的文件夹中。我试图在 python 的上下文中解决这个问题,但这个问题实际上与 python 无关...
目前我的 gradle 文件如下所示:
configurations { python }
dependencies {
python group: 'github.dpeger', name: 'py-utils', version: '1.6', ext: 'zip'
python group: 'github.dpeger', name: 'py-test', version: '1.6', ext: 'zip'
}
task cleanPythonDependencies(type: Delete) { delete 'lib/python' }
tasks.clean.dependsOn cleanPythonDependencies
task importPythonDependencies(type: Copy) {
dependsOn cleanPythonDependencies
from {
configurations.python.collect { zipTree(it) }
}
into 'lib/python'
}
然而,这会将 python
配置中的所有依赖项提取到文件夹 lib\pyhton
中,而不使用工件的名称。
我想要的是 py-utils
被提取到 lib\pyhton\py-utils
和 py-test
到 lib\pyhton\py-test
.
假设您希望将 py-utils 提取到 lib\pyhton\py-utils 并将 py-test 提取到 lib\pyhton\py-test,这应该可以完成工作:
task importPythonDependencies() {
dependsOn cleanPythonDependencies
String collectDir = 'lib/python'
outputs.dir collectDir
doLast {
configurations.python.resolvedConfiguration.resolvedArtifacts.each { artifact ->
copy {
from zipTree( artifact.getFile() )
into collectDir + '/' + artifact.name
}
}
}
}
我正在寻找一种方法来将特定配置的项目依赖项提取到工作区文件夹中。由于可能存在多个依赖项,我想将每个工件提取到一个具有工件名称的文件夹中。我试图在 python 的上下文中解决这个问题,但这个问题实际上与 python 无关...
目前我的 gradle 文件如下所示:
configurations { python }
dependencies {
python group: 'github.dpeger', name: 'py-utils', version: '1.6', ext: 'zip'
python group: 'github.dpeger', name: 'py-test', version: '1.6', ext: 'zip'
}
task cleanPythonDependencies(type: Delete) { delete 'lib/python' }
tasks.clean.dependsOn cleanPythonDependencies
task importPythonDependencies(type: Copy) {
dependsOn cleanPythonDependencies
from {
configurations.python.collect { zipTree(it) }
}
into 'lib/python'
}
然而,这会将 python
配置中的所有依赖项提取到文件夹 lib\pyhton
中,而不使用工件的名称。
我想要的是 py-utils
被提取到 lib\pyhton\py-utils
和 py-test
到 lib\pyhton\py-test
.
假设您希望将 py-utils 提取到 lib\pyhton\py-utils 并将 py-test 提取到 lib\pyhton\py-test,这应该可以完成工作:
task importPythonDependencies() {
dependsOn cleanPythonDependencies
String collectDir = 'lib/python'
outputs.dir collectDir
doLast {
configurations.python.resolvedConfiguration.resolvedArtifacts.each { artifact ->
copy {
from zipTree( artifact.getFile() )
into collectDir + '/' + artifact.name
}
}
}
}