无法在Gradle中创建Zip归档文件

14

我想创建一个简单的 Zip 存档文件,其中包含我资源目录中的所有 JavaScript 文件。

这是代码:

  task zip(type:Zip){
    from ('resources/'){
        include '*.js'
    }
    into 'resources'
}

某些原因,这似乎不起作用。我听很多人说只需要 frominto 就能创建一个归档文件。有人可以帮帮我吗?我正在使用Gradle v1.0。先谢谢了。

2个回答

22

可以尝试类似这样的方法(文档):

task zip(type:Zip) {
 from ('resources/')
 include '*.js'
 into 'resources' // note that this specifies path *in* the archive
 destinationDir file('dir') // directory that you want your archive to be placed in
}

5
在Windows上使用Gradle 1.10时,当我向destinationDir参数传递字符串时,出现了错误。但是,当我传递一个File对象时,如destinationDir(file("target")),它似乎可以正常工作。 - amacleod
2
destinationDir的setter函数确实需要一个文件。 - JoeG

10
task someTask << {

    // other code...

    task(zipResources, type: Zip) {
        destinationDir new File(projectDir, 'resources')
        archiveName 'resources.zip'
        from 'src/main/webapp'
        include '*.js'
    }.execute()

    task(zipSomethingElse, type: Zip) {
        destinationDir buildDir
        archiveName 'source-code.zip'
        from 'src/main/java'
        include '**/*.java'
    }.execute()

    // some other code...

}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接