I have a gradle task that executes a command-line tool that creates several zip files. After generating the files, I want Gradle to publish the resulting zip files to a Maven repository. Each zip file has its own artifactId and groupId (that can be derived from the filename of the zip file). The number and names of the zip files are not known beforehand and may be different on each run.
I’m not a Gradle expert but after studying the documentation I think I should declare the zip files as publications for the maven-publish plugin. I know how to do this with static files and tasks that generate a single archive file. I could not find examples on how to do this with multiple archives from a single task, as in my case.
Let’s say my build.gradle
looks like this:
apply plugin: 'base'
apply plugin: 'maven-publish'
task init << {
buildDir.mkdirs()
}
task makeZipfiles(type: Exec, dependsOn: 'init') {
workingDir buildDir
commandLine 'touch', 'test1.zip', 'test2.zip'
// actual result files will be different on each run
}
publishing {
publications {
// ??? Publication of all files from task makeZipfiles,
// each with its own groupId and artifactId
}
}
I have been able to create publications by iterating over the files in the build directory, but that only works if I first run the makeZipfiles task and then run the publish task. What I want is to make the publish tasks depend on the makeZipfiles task, using the output files of the makeZipfiles task for publication.
What is a correct way of defining tasks, artifacts and/or publications to achieve the desired result?