Gradle goodness:unpacking an Archive

Source: Internet
Author: User
Tags unpack

To create a archive with Gradle are easy. We have the several tasks like Zip, Tar, Jar, War and Ear to create a new archive. But there was no UnZip or Untar to unpack a 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 a 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 in the dist.zip directory src/dists . We unpack the contents to the directory build/unpacked/dist :

View Sourceprint? 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, the tasks of type Copy automatically support Gradle ' s incremental build support. This means if the task have been executed once and the file and output in the directory have not a change dist.zip build/unpacked/dist t The He 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.