Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle, extracting a dependency zip and using the content in its file?

I have a Gradle build project that is dependent on another project. My project is supposed to pull a zip archive from the other project and extract the archive. One of the files inside the archive is called "name.txt", and inside it is a string that I need to pass as an argument inside my "build" task.

def unzippedDir = file('build/dependencies/unzippedDir').getAbsolutePath()

configurations {
  zipArchive
}

dependencies {
  ziparchive "<path>"
}

task unzip(type:Copy) {
  into unzippedDir from zipTree(configurations.zipArchive.singleFile)
}

task build {
  dependsOn unzip
  def name = new File(unzippedDir + '/name.txt').text
  // <the test of the build steps that uses the "name" variable>
}

But I am getting a "No File or Directory" error for "name.txt". Am I doing something wrong?

What I am seeing in the extracted directory though, is that only one of the files inside the zip archive ended up in the unzippedDir. "name.txt" is not there even though another file is. Does this mean I did something wrong with the unzip task?

like image 998
JimmyT Avatar asked Dec 24 '22 16:12

JimmyT


1 Answers

Try this:

and check your configuration name because of a spelling mistake there.

def unzippedDir = "$buildDir/dependencies/unzippedDir" 

task unzip(type: Copy) {
    configurations.zipArchive.asFileTree.each {
        from(zipTree(it))
    }
    into unzippedDir
}

build.dependsOn unzip
like image 150
LazerBanana Avatar answered Dec 26 '22 11:12

LazerBanana