无法在Gradle中创建Zip存档

时间:2012-07-15 20:05:49

标签: zip gradle

我正在尝试创建一个简单的Zip存档,其中包含资源目录中的所有javascript文件

以下是代码:

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

由于某些原因,这似乎不起作用。我听过很多人说你需要的只是frominto来创建档案。有人可以帮我吗?我正在使用Gradle v1.0。提前致谢。

2 个答案:

答案 0 :(得分:22)

尝试这样的事情(docs):

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
}

答案 1 :(得分: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...

}