2014-04-03 57 views
5

我想提取一個不帶PARENT目錄的依賴zip文件,在使用Gradle提取時排除某個文件。如何提取沒有第一個目錄使用Gradle?

這裏是我有這個工作,但感覺不對,我希望有一個更好的辦法做到這一點

Zip文件,我正在提取

jar tf parent-folder-name.zip 


parent-folder-name/bin/something.sh 
parent-folder-name/bin/something.bat 
parent-folder-name/lib/somelib.jar 

選項1

task explodeToDist1(type: Copy) { 
    from zipTree(configurations.extractDist.singleFile) 
    exclude "**/lib/**" 
     eachFile { 
      def newPath = it.relativePath.segments[1..-1].join("/") 
      it.relativePath = RelativePath.parse(true, newPath) 
     } 
    into 'build/dist' 
    doLast { 
     def path = buildDir.getPath() + "/dist/parent-folder-name" 
     def dirToDelete = new File(path) 
     dirToDelete.deleteOnExit() 
    } 
} 

選項2

task explodeToDist2 << { 
     def unzipDir = new File('build/unzipTmp') 
     copy { 
      from zipTree(configurations.extractDist.singleFile) 
      into unzipDir 
     } 
     def rootZipDir = unzipDir.listFiles()[0] 
     fileTree(rootZipDir){ 
       exclude "**/lib/**" 
     }.copy { 
      into 'src/dist' 
     } 
     unzipDir.deleteDir() 
} 

要我選項2感覺更好,但我不知道是否有更好的方法在搖籃做到這一點?

+1

只需交聯,同樣的問題在搖籃論壇上提出 - HTTP://論壇。 gradle.org/gradle/topics/how_to_extract_without_first_directory_using_gradle – Radim

回答

相關問題