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. Html5本地存储+本地数据库+离线存储

    首先介绍什么叫存储: cache:通常把它叫做缓存,功能就是把从DB,或者磁盘拿出来的东西放在缓存里面,这样的话可以减少读取磁盘的IO. 磁盘文件:通常把一些图片或者一些视频都存放在磁盘上. 数据库: ...

  2. webpack-loader原理

    loader loader 是导出为一个函数的 node 模块.该函数在 loader 转换资源的时候调用.给定的函数将调用 loader API,并通过 this 上下文访问. loader配置 { ...

  3. Python入门-生成器和生成器表达式

    昨天我们说了迭代器,那么和今天说的生成器是什么关系呢? 一.生成器 什么是生成器?说白了生成器的本质就是迭代器. 在Python中中有三种方式来获取生成器. 1.通过生成器函数 2.通过各种推导式来实 ...

  4. Linux基础之-正则表达式(grep,sed,awk)

    一. 正则表达式 正则表达式,又称规则表达式.(英语:Regular Expression,在代码中常简写为regex.regexp或RE),计算机科学的一个概念.正则表达式是对字符串操作的一种逻辑公 ...

  5. 001服务注册与发现Eureka

    1.POM配置 和普通Spring Boot工程相比,仅仅添加了Eureka Server依赖和Spring Cloud依赖管理 <dependencies> <!--添加Eurek ...

  6. c 读取整个文件内容

    char* textFileRead(char* filename){char* text;FILE *pf = fopen(filename,"r");fseek(pf,0,SE ...

  7. 在Linux中安装redmine

    Redmine是用Ruby开发的基于web的项目管理软件,是用ROR框架开发的一套跨平台项目管理系统. 如下即为安装步骤: (1)配置ruby环境,可用rvm进行安装匹配,参考http://ruby- ...

  8. ubuntu下root不能复制 abc用户下的软连接文件

    使用root用户去复制,提示权限不足: 那么这个软连接是个什么东西??

  9. 缓存服务Ehcache方案

    1  Ehcache简介 在Java项目广泛的使用.它是一个开源的.设计于提高在数据从RDBMS中取出来的高花费.高延迟采取的一种缓存方案.正因为Ehcache具有健壮性(基于java 开发).被认证 ...

  10. 页面引入(include)方式的研究及性能比较

    1. 应用Html中的框架(iframe) 目前大多数门户网站都应用iframe来进行页面上广告的投放,就是将不同的广告分别应用iframe投放到主页面上,优点是效率高,互不影响,缺点是不符合网页标准 ...