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
$

Gradle Goodness: Unpacking an Archive的更多相关文章

  1. Gradle Goodness: Copy Files with Filtering

    Gradle Goodness: Copy Files with Filtering Gradle's copy task is very powerful and includes filterin ...

  2. Gradle Goodness: Task Output Annotations Create Directory Automatically

    Gradle Goodness: Task Output Annotations Create Directory Automatically One of the great features of ...

  3. Gradle Goodness: Init Script for Adding Extra Plugins to Existing Projects

    Gradle Goodness: Init Script for Adding Extra Plugins to Existing Projects Gradle is very flexible. ...

  4. yum update 执行报错: error : unpacking of archive failed on file /usr/.../...;5d26ff7c: cpio : symlink

    早前已发现有台机一直在报这么个错误, 一用yum update 就报一堆: Error: unpacking rpm package ..... error: xxxx : install faile ...

  5. Gradle Goodness: Adding Tasks to a Predefined Group

    In Gradle we can group related tasks using the group property of a task. We provide the name of our ...

  6. Gradle Goodness: Using and Working with Gradle Version

    To get the current Gradle version we can use the gradleVersion property of the Gradle object. This r ...

  7. Gradle Goodness: Skip Building Project Dependencies

    If we use Gradle in a multi-module project we can define project dependencies between modules. Gradl ...

  8. Gradle Goodness: Continue Build Even with Failed Tasks

    If we run a Gradle build and one of the tasks fails, the whole build stops immediately. So we have f ...

  9. Gradle Goodness: Rename Ant Task Names When Importing Ant Build File

    Migrating from Ant to Gradle is very easy with the importBuild method from AntBuilder. We only have ...

随机推荐

  1. Java SortedSet为什么可以实现自动排序?

    Set中的SortedSet(SortedSet为TreeSet的实现接口),它们之间的继承关系如下: java.util.Set; java.util.SortedSet; java.util.Tr ...

  2. inline-block元素,在同一行上下显示

    两个元素使用了inline-block,并列显示时,会上下显示,给人感觉不在同一行 原因:其中一个元素使用了overflow:hidden,导致了基线变更 解决:1.另一个元素也添加overflow: ...

  3. ionic2生命周期

    生命周期: ionViewDidLoad(){ console.log("1.0 ionViewDidLoad 当页面加载的时候触发,仅在页面创建的时候触发一次,如果被缓存了,那么下次再打开 ...

  4. 解决方案看起来是受源代码管理,但无法找到它的绑定信息。保存解决方案的源代码管理设置的MSSCCPRJ.SCC文件或其他项可能己被删除。

    Visual Studio 2015 + SVN 开发环境,今天打开项目,就报了下面这个错误,先前是好好的! 解决方案看起来是受源代码管理,但无法找到它的绑定信息.保存解决方案的源代码管理设置的MSS ...

  5. 关于pom版本提交不成功的问题

    今天碰到个问题:我在原来的一个pom项目的client服务里面修改了一个java类,但是没有升级版本.然后再预发环境更新后,从显示的日志来看,仍然是我修改前的版本. 这就奇怪了,看了svn确实已经提交 ...

  6. MVC Dropdownlist数据绑定 默认值

    @Html.DropDownList("Data", (SelectList)ViewBag.Data, new { @class = "form-control cho ...

  7. C# Request获取URL常见用法

    如果测试的url地址是http://www.test.com/testweb/default.aspx, 结果如下: Request.ApplicationPath: /testweb Request ...

  8. 【Leetcode】【Medium】Populating Next Right Pointers in Each Node

    Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *nex ...

  9. Grunt 使用(二)uglify插件压缩javascript代码

    本文在配置grunt基本环境的基础下,讲解如何使用grunt-contrib-uglify进行javascript压缩 本文只介绍了grunt-contrib-uglify插件的一种压缩方式适用于大部 ...

  10. 020hashlib模块

    #里面内容没有见过,可能会比较难懂,需要找资料.我只是记录了视频中的用法,其他理解的东西,我直接理解,就没有写下来了.下面内容是视频演示过程 import    hashlib m = hashlib ...