我有一个gradle脚本,类似于以下内容:
apply plugin: 'java'
apply plugin: 'maven'
defaultTasks 'build'
ext.basedir = file('.').getAbsolutePath()
repositories{
maven { url "http://package.repo.com:8081/nexus/content/repository
}
configurations.all {
// check for updates every build
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
dependencies {
compile group:'com.repo.wwpd', name:'kernel_utilities', version:'3.0.0', changing:true
}
task copy_dependencies(type: Copy) {
from configurations.compile
into basedir+'\\install'
include '*'
{ FileTree ioTree = fileTree(dir: "C:\\Users\\username\\install") }
ioTree.each { f ->
copy {
from tarTree(resources.gzip(f))
into "C:\\Users\\user\\test"
}
}
}
目标是获取依赖项,将它们移动到安装文件夹,然后将它们从tar文件中提取到测试文件夹。
问题似乎是在下载依赖项之前执行任务。因此,如果文件已经存在于安装中,它可以正常工作,但如果安装文件夹为空,则结果是一个空的测试文件夹,但是一个完整的安装文件夹。
答案 0 :(得分:3)
[编辑 - 更新评论Peter N.]
这应该是解决你案件的一种方法;请注意,它包含两个任务,选择满足您需求的任务:简单复制VS完全提取
def installDir = "${buildDir}/install"
def extractDir = "${buildDir}/extract"
// task to copy dependencies
task copyDependencies(type: Copy) {
from configurations.compile
into installDir
}
// task to extract dependencies
task extractDependencies(type: Copy) {
from configurations.compile.collect{tarTree (it)}
into extractDir
}