2012-07-15 115 views
14

我試圖創建一個包含在我的資源目錄無法在搖籃

這裏所有的JavaScript文件的簡單Zip文檔創建Zip文件的代碼:

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

這不由於某種原因似乎工作。我聽到很多人說,你需要的只是一個frominto創建一個檔案。有人可以幫我嗎?我正在使用Gradle v1.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 
} 
+5

在Windows上使用搖籃1.10,我當我給destinationDir字符串得到一個錯誤,但它似乎好工作,當我給它一個文件,像'destinationDir(文件(「目標」))' – amacleod 2014-02-27 21:23:16

+2

destinationDir setter確實採取文件 – JoeG 2014-04-03 21:19:32

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... 

} 
+0

非常簡單,謝謝! – spy 2016-09-28 00:51:08