how to put folder into a tar file with gradle

时间:2016-12-14 07:10:46

标签: gradle zip directory tar

I am new to gradle. I want to create a filename.tar file which includes (filename.war and data/config/*.properties). The war file stays inside build/libs. The requirement is: inside tar file, we need to have folder data/config and all properties files under that folder. The war file stays in the same level with data folder.

Here is what i have,

task tarz(type: Tar) {
 archiveName = 'filename'
 from 'build/libs','data/config'
 include '*.war','*.properties'
 destinationDir = file('build/tar')
 extension 'tar'
 compression = Compression.GZIP
}

this above script is only copy properties files into tar, not the folder. And the name of the file is 'filename', not 'filename.tar'

Please help me.

2 个答案:

答案 0 :(得分:4)

这就是我所做的

task tarz(type: Tar) {
 archiveName = 'aaa.tar'
 into ('/'){
    from 'build/libs'
    include '*.war'
 }

 into ('data/config'){
    from 'data/config'
    include '*.properties.*'

 }

destinationDir  file('build/tar')
 extension 'tar'
 compression = Compression.GZIP
}

答案 1 :(得分:0)

这是我的Spring Boot App示例

task tgzTask(type: Tar) {
    into('app/') {
        from 'build/libs'
        include '*.jar'
    }
    into('app/') {
        from 'build/resources/main/banner.txt'
    }
    into('app/config') {
        from 'build/resources/main/config'
        from 'build/resources/main/banner.txt'
    }
    into('app/config/sql') {
        from 'build/resources/main/sql'
    }
    
    destinationDirectory = file('build/distributions')
    extension 'tgz'
    compression = Compression.GZIP
}

有关更多信息,Tar manual