6

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?

1
  • 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?
    – JimmyT
    Jun 30, 2017 at 15:45

1 Answer 1

12

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
9
  • Does this mean I have to point archiveDir at the location where the dependency archive is stored? Where is that?
    – JimmyT
    Jun 30, 2017 at 15:59
  • @JimmyT archive dir is the directory where your archive is. I dont know where you have it. Jun 30, 2017 at 16:00
  • the archive is pulled down from an artifactory repository. It is stored somewhere automatically by gradle. So I do not know explicity where it is.
    – JimmyT
    Jun 30, 2017 at 16:03
  • i see you didnt mention that ;p lthen yes you are going to fetch it from artifactory. i Iwll edit the answer Jun 30, 2017 at 16:04
  • 1
    Fantastic, this is it. Thank you.
    – JimmyT
    Jun 30, 2017 at 16:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.