zoukankan      html  css  js  c++  java
  • Gradle Goodness: Unpacking an Archive

    To create an archive with Gradle is easy. We have several tasks like Zip, Tar, Jar, War and Ear to create a new archive. But there is no UnZip or UnTar to unpack an archive in Gradle. To unpack an archive we must use the Copy task and copy the contents of the archive to a specified destination directory. In Gradle we can use the zipTree() method to access the contents of an archive. So in our copy definition the source is the contents of the archive we access with the zipTree() method.

    In the following build file we see a simple task to unzip a ZIP file with the name dist.zip in the directory src/dists. We unpack the contents to the directory build/unpacked/dist:

    0.task unzip(type: Copy) {
    1.def zipFile = file('src/dists/dist.zip')
    2.def outputDir = file("${buildDir}/unpacked/dist")
    3. 
    4.from zipTree(zipFile)
    5.into outputDir
    6.}

    The good thing is that tasks of type Copy automatically support Gradle's incremental build support. This means that if the task has been executed once and the dist.zip file and output in the directory build/unpacked/dist has not change the task is up-to-date and isn't executed.

    We get the following output if we run the task twice:

    $ gradle unzip
    :unzip
     
    BUILD SUCCESSFUL
     
    Total time: 2.867 secs
    unzip mrhaki$ gradle unzip
    :unzip UP-TO-DATE
     
    BUILD SUCCESSFUL
     
    Total time: 2.606 secs
    $
  • 相关阅读:
    javascript 写一个随机范围整数的思路
    Promise中的next 另一个用法
    继上一篇随笔,优化3张以上图片轮播React组件
    低性能3张图片轮播React组件
    用函数式编程思维解析anagrams函数
    Python time time()方法
    torch.view().expand()
    pytorch中的top_K()函数
    设定学习率衰减
    两个集合求交集
  • 原文地址:https://www.cnblogs.com/GoAhead/p/4189018.html
Copyright © 2011-2022 走看看