I would like to create a dynamic Zip task taking the distributions of 2 subprojects in order to merge them
Here is an extract of the code I use
TaskProvider createDistribution(String proj) {
// *** Distribution task ***
String distribTaskName = "distribute${proj}";
def u = tasks.register (distribTaskName, Zip) {
doFirst {
println "task for ${proj}"
//Get archive from project
def projFile = tasks.getByPath(":${proj}:distZip").outputs.files.singleFile
def projTree = zipTree(projFile)
//Get application archive
def appliFile = tasks.getByPath(":application:distZip").outputs.files.singleFile
def appliTree = zipTree(appliFile)
from projTree.files
from appliTree.files
include '**/*.jar'
archiveName "${distTask.baseName}.zip"
duplicatesStrategy 'exclude'
}
doLast{ println "Merging ${projFile.absolutePath} & ${appliFile.absolutePath} into ${archivePath}" }
}
return u
}
def program = ["proj1", "proj2", "proj3"]
distributedProjects.each {
TaskProvider dis = createDistribution (it)
afterEvaluate{
dis.configure {
dependsOn tasks.getByPath(":application:distZip")
dependsOn tasks.getByPath(":$proj:distZip")
}
}
proj1, proj2 and proj3 are subprojects of my main project where I defined this above code.
My issue is, as written above, task does not run as no source is identified.
Skipping task ‘:distributeproj1’ as it has no source files and no previous output files.
If I remove the doFirst block in createDistributionFunction, configuration fails as the distributionZip is not already created.
Could not create task ‘:distributeproj1’.
Cannot expand ZIP ‘[proj1 zip path]’ as it does not exist.
How can I handle this issue ? I’m trying to force the task to get over the “no source” but I don’t find any tips on forum.