I am working with a project that ships binaries (compiled java classes) as a zip file. The zip contains various files, but the interesting ones are Java libraries packaged as JAR files inside the zip. The zip itself has been uploaded to my organization’s Artifactory.
Consider a structure like this:
project.zip
|- libs
| |- a.jar
| '- b.jar
|- resources
'- i18n
I have written a task that makes use of Copy to unzip the file contents, which works wonderfully.
task assemble(type: Copy) {
assert configurations.main.files.size() == 1
inputs.file configurations.main.files[0]
outputs.file 'project/lib/a.jar'
from zipTree(inputs.getFiles().getSingleFile())
into projectDir
include 'project/**'
ant.chmod(dir: new File(projectDir, 'project/bin'), includes: '*', perm: 'ugo+rx')
}
However, the challenge I have is in figuring out how to “export” these files so that I can depend on them from another project. I suppose normally for Java projects (apply plugin java) this happens automagically since anything using the Jar task will be added to Gradle’s artifacts list for the current project.
What I would like to do is declare a dependency on this project from another, e.g.:
dependencies {
compile project(':project')
}
and have the extracted jar files automatically added to the classpath.
Yes, this should be straight forward with copy task that runs zipTree on the artifact. You then need to define the output jars as artifacts of your project. Use the builtBy property to link the copy task to the artifacts.
Great, thank you. It looks like this will only add a single file as an artifact – would I then need some way to loop across all the files in the output fileTree?