0

I am working on one gradle script where I need to create the zip file.Below are my contents in the workspace but I need few folder inside the zip file and the zip file should be create with name application-data-1.0.zip.I need only three folder inside that zip file data,sql and services .As per my understanding I need to use distribution plugin.Could someone tell me how could I do that?

-rw-r--r-- 1 jenkins jenkins      38 Mar 11 22:39 at.properties
drwxr-xr-x 3 jenkins jenkins    4096 Mar 11 22:39 data
-rw-r--r-- 1 jenkins jenkins      38 Mar 11 22:39 pd.properties
-rw-r--r-- 1 jenkins jenkins    5532 Mar 11 22:39 maven.xml
-rw-r--r-- 1 jenkins jenkins   74384 Mar 11 22:39 pom.xml
-rw-r--r-- 1 jenkins jenkins      37 Mar 11 22:39 sbx.properties
-rw-r--r-- 1 jenkins jenkins     595 Mar 11 22:39 project.xml
-rw-r--r-- 1 jenkins jenkins    1020 Mar 11 22:39 project.properties
drwxr-xr-x 3 jenkins jenkins    4096 Mar 11 22:39 sql
drwxr-xr-x 3 jenkins jenkins    4096 Mar 11 22:39 services
-rw-r--r-- 1 jenkins jenkins      40 Mar 11 22:39 tst.properties
-rw-r--r-- 1 jenkins jenkins 5656258 Mar 26 15:51 application-data-1.0.zip
unknown
  • 1,815
  • 3
  • 26
  • 51
  • Read http://gradle.org/docs/current/userguide/working_with_files.html#sec:archives and https://gradle.org/docs/current/dsl/org.gradle.api.tasks.bundling.Zip.html, and try something. – JB Nizet Apr 02 '15 at 17:19
  • I tried and able to make the zip file but I am facing an issue.I used the below code bit it is not giving me the correct output – unknown Apr 02 '15 at 18:17
  • I tried the below code to make the zip file but it is move all the directrioes inside data directory and create build/distribution/abz.zip file which I don't want.I need it copied data sql and services folder from cuurent workspace and make zip file in the existing workspace with name abc-1.0.zip apply plugin: 'java' task zip(type: Zip) { from 'data' into('application-data') { from configurations.runtime } } – unknown Apr 02 '15 at 19:04
  • @user1513848 you just need a task of type `Zip` configured appropriately. What's the problem? – Opal Apr 07 '15 at 07:26

1 Answers1

0

Using a custom zip task, you can do something like:

task applicationDistZip(type: Zip) {
    archiveBaseName.set("application-data")
    archiveVersion.set('1.0')
    from ('.') {
        include 'data/**'
        include 'services/**'
        include 'sql/**'
    }
}

Using the distribution plugin:

distributions {
    application {
        baseName = 'application-data'
        version = '1.0'
        contents {
            from ('.') {
                include 'data/**'
                include 'services/**'
                include 'sql/**'
            }
        }
    }
}

To generate the zip, just run the command applicationDistZip

smac89
  • 39,374
  • 15
  • 132
  • 179