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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With