How do I create a tar file from selected files from different directories?

(Dean Schulze) #1

I’m trying to convert my bash scripts to Gradle, but I’m not finding what I need in Gradle. I’m currently building a .tgz archive from multiple files from different directories (I don’t want their paths in the .tgz file). Does the tarFiles task allow selecting files by name from different directories?

I’ll also need to verify that these files and directories exist, but that can be done in a dependency.

(Dean Schulze) #2

I’ve added this task, but it doesn’t create anything. The variable files is an ArrayList of file names, and they exist.

task tgzTask(type: Tar) {
   include files
 baseName = 'test'
 destinationDir = file('.')
 extension = 'tgz'
 compression = Compression.GZIP
  println tgzTask.archiveName
println relativePath(tgzTask.destinationDir)
println relativePath(tgzTask.archivePath)
println files.size
files.each {println it}

(Peter Niederwieser) #3

‘include’ defines an include filter. Replace ‘include’ with ‘from’.

(Dean Schulze) #4

Thanks, Peter. That worked.