unbekant
unbekant

Reputation: 1555

Gradle untar multiple files to different directories in single copy task

I am writing a gradle script that downloads a series of tarballs from our repo manager. Let's suppose that I have a temp dir that looks as follows:

temp/lib_x86.tar.gz

temp/lib_armv7.tar.gz

temp/lib_armv7s.tar.gz

temp/lib_arm64.tar.gz

What I want to do is untar all of them with a single copy task into different directories, since all tarballs contain the same static library but compiled for a different architecture. My ultimate goal is creating a fat library out of those, but can't figure out a neat way of configuring the copy task. So far I have:

copy {
    fileTree(dir: 'temp').include('*.tar.gz').each {File simLib ->
        println "Untar ${simLib.name}"
            from tarTree(resources.gzip(simLib.name))
            into "temp/${simLib.name}"
            include '*.a'           
        }
}

Problem is it seems to work for only one of the files even though the print statement shows that it processes all 4 files. Any ideas?

Upvotes: 2

Views: 3521

Answers (1)

Opal
Opal

Reputation: 84904

Ok, have worked it out. In the example you provided copy block will be configured once - last wins - and to be more specific the last setting on the list will cover all previous. It needs to be reversed. It can be done in the following way:

fileTree(dir: 'tmp').include('*.tar.gz').each { simLib ->
   copy {
      println "Untar $simLib.name"
      def name = simLib.name - '.tar.gz'
      from tarTree("tmp/${simLib.name}")
      into "tmp/$name"       
   }
}

Demo is here.

Upvotes: 2

Related Questions