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. PHP开发框架CodeIgniter

    CodeIgniter 是一套给 PHP 网站开发者使用的应用程序开发框架和工具包. 通过下面四步来安装 CodeIgniter: 解压缩安装包: 将 CodeIgniter 文件夹及里面的文件上传到 ...

  2. POI 2000 ------Stripes

    Stripes Time Limit:1000MS Memory Limit:30000KBTotal Submit:94 Accepted:43 Description Stripes is a t ...

  3. What is the relation of theme and it's derived theme.

    You know, a theme can derive from other theme in two ways: xx.xxx implicit way and parent="xxx& ...

  4. 云计算的三种模式:IaaS、PaaS和SaaS

    云计算主要分为三种服务模式,而且这个三层的分法重要是从用户体验的角度出发的: 1. Software as a Service,软件即服务,简称SaaS,这层的作用是将应用作为服务提供给客户. 2. ...

  5. vue中全局引入bootstrap.css

    1.首先在官网上下载bootstrap的压缩包(必须是官网上下载的) 将压缩包解压后引入在项目文件夹下面.如下图所示: 2.在main.js中引入 import './assets/bootstrap ...

  6. ArcGIS for JavaScript 关于路径开发的一些记录(三)

    最近被一个bug困扰了两天~ 我新发布了一个NAserver(路径分析服务),但是放在之前的代码里面发现不能生成路径.经过我的调试发现并没有代码并没有报错,并且能够返回所生成路径的Graphic la ...

  7. vs2010开发activex(MFC)控件/ie插件(二):js传参数

    原文:http://blog.csdn.net/yhhyhhyhhyhh/article/details/50802075  js传参数给activex控件. 过程为:js变量通过activex类的属 ...

  8. Oracle案例07——ORA-28000: the account is locked

    遇到这个错误,一般我们想到的是数据库用户被锁,只需要执行用户解锁即可恢复,但这里之所以写出来是因为比较奇葩的一个问题. 昨天下午接同事信息,说一个用户连接报被锁,经过沟通发现其实连接一个ADG的备库作 ...

  9. compositionstart事件与compositionend事件

    https://blog.csdn.net/u013096088/article/details/52873562

  10. Eclipse 中 SVN 提交过滤