0
我有這樣的結構在一個zip文件提取的文件夾,並創建一個jar
classes
|--com: A.class, B.class
|--org: C.class, D.class
|--android: X.class
|--stuff: Stuff.inf, info.txt
我希望能夠與.class文件只提取文件夾:COM,組織,機器人。並把它們放在一個罐子裏。 到目前爲止,我已經做到了這一點:
task createJar {
//unzip the file
FileTree zip = zipTree('runtime.jar')
FileTree zip2 = zip.matching {
include 'classes/**/*.class'
}
zip2.each { file -> println "doing something with $file" }
//create the jar
jar{
from zip2
destinationDir file('GradleTests/testResult')
}
}
但我得到它的類文件夾中的罐子,如:classes/org/apache/http/entity/mime/content/StringBody.class
,我希望它這樣的:org/apache/http/entity/mime/content/StringBody.class
任何想法如何? 謝謝!
使用Gradle(1.11)的當前版本,此解決方案無法運行,您將得到一個ClassCastException,因爲這些段不能被轉換爲RelativePath。我有一個類似的問題,有一些替代解決方案。請查看這裏[如何提取沒有第一個目錄使用Gradle?](http://stackoverflow.com/questions/22844296/how-to-extract-without-first-directory-using-gradle?noredirect=1#comment34866075_22844296) – dineshr 2014-04-04 06:41:56