我有一个gradle任务来创建目录的zip存档。 gradle任务是:
task archiveReports(type: Zip) {
from '/projects/Reports/*'
archiveName 'Reports.zip'
}
当我运行命令' gradle archiveReports'时,它显示构建成功。但是,没有创建zip文件。
我在这里错过了什么吗?
答案 0 :(得分:34)
我找到了解决方法: 它现在为我工作。
task myZip(type: Zip) {
from 'Reports/'
include '*'
include '*/*' //to include contents of a folder present inside Reports directory
archiveName 'Reports.zip'
destinationDir(file('/dir1/dir2/dir3/'))
}
答案 1 :(得分:2)
添加到接受的答案中, 6.7级,
task packageDistribution(type: Zip) {
archiveFileName = "my-distribution.zip"
destinationDirectory = file("$buildDir/dist")
from "$buildDir/toArchive"
}
archiveName被弃用。
答案 2 :(得分:0)
https://docs.gradle.org/current/userguide/working_with_files.html#sec:creating_archives_example
task packageDistribution(type: Zip) { archiveFileName = "my-distribution.zip" destinationDirectory = file("$buildDir/dist") from "$buildDir/toArchive" }
答案 3 :(得分:0)
使用 Kotlin DSL
tasks.register<Zip>("packageDistribution") {
archiveFileName.set("my-distribution.zip")
destinationDirectory.set(layout.buildDirectory.dir("dist"))
from(layout.buildDirectory.dir("toArchive"))
}
使用 Groovy
tasks.register('packageDistribution', Zip) {
archiveFileName = "my-distribution.zip"
destinationDirectory = layout.buildDirectory.dir('dist')
from layout.buildDirectory.dir("toArchive")
}