My project has a remote dependency which is really just a zip of certain files, which needs to be unzipped somewhere, so that the build can generate new java sources from the files. (I’m speaking generically to focus on the core problem and not on the specifics)
I wouldn’t expect this to be so hard, but I’ve been unable to get it working. Here’s what I’ve created:
I defined a new configuration:
configurations {
newConf
}
Later, I’ve defined a single dependency for this confiuguration. It resolves to the zip file I need to explode:
dependencies {
newConf "group:name:version@zip"
}
So far this all smells correct to me, though if anybody disagrees, I’m listening.
Lastly I need to define a task that explodes the zip into a directory, which then becomes the input for a later code-generation command.
task explodeModel {
description = "unzip model into the specified 'modelSrc' directory"
//input is a "files" collection (usually just one: the zip)
//output is the specified modelSrc dir
File modelSrc = new File("$buildDir/modelSrc")
outputs.files modelSrc
doLast {
configurations.newConf.allArtifacts.each { artifact -> println artifact }
}
}
Obviously doLast isn’t unzipping anything just yet, I’m just trying to get an absolute path to the zipfile itself, and thats where I’m stuck. I have no idea how to get a path to the file so I can unzip it. Any help?
Many thanks
I did something similar in a plugin that I wrote. This should work for you:
The assumption is that there’s only one file. The return type is
java.io.File.For more information check this class GaePlugin.groovy. The method of relevance is
configureDownloadSdk. The task that does the unzip is GaeDownloadSdkTask.groovy.