压缩文件并将其移动

时间:2018-02-08 13:12:40

标签: gradle groovy

我正在尝试压缩模块中的内容,排除build文件夹但它没有运行。我在任务之外做println并且有效但在任务中没有任何内容。

task fullZip(type: Zip) {
    baseName = 'client' //name of the module
    from 'client' //name of the module
    exclude 'build'
    into '../docker/client'
    doFirst { println 'before zip' }
    doLast { println 'after zip' }

}

这是一个多模块项目,我已经运行gradle clean buildgradle build其他模块工作得很好,但他们的任务是复制一个jar,我在最后使用assemble.dependsOn那些任务。在这种情况下,这不起作用。

我只想压缩模块并将其移动到我将解压缩的其他目录。

1 个答案:

答案 0 :(得分:1)

聊天讨论摘要:

task fullZip(type: Zip) {
    baseName = 'client'
    from projectDir
    exclude 'build'
    destinationDir = file('../docker/client')
}

build.dependsOn fullZip

主要问题是from参数中的相对路径,它确实有效,因为它是相对于项目目录解释的。

此外,根据the docsinto方法......

  

指定文件存档中的目标目录 。目的地按Project.file(java.lang.Object)评估。不要将其与AbstractArchiveTask.getDestinationDir()混合使用,int position = YOUR_RECYCLERVIEW_ITEM_POSITION; yourList.remove(position); yourAdapter.notifyDataSetChanged(); 指定存档的输出目录。

这两种方法混在一起。最后,通过任务依赖注册将任务添加到构建生命周期中。