Hello all,
I have a custom component type with two binaries. Each binary has a task, one of which depends on the other. How can I make that task dependency a reality without knowing the component names ahead of time?
Using this gist as an example, I need tasks.generateCmpOneBinaryTwo to depend on tasks.generateCmpOneBinaryOne (similar for cmpTwo’s tasks).
Thanks, Chris
I seem to have something that works, whether it’s the best approach I’m not sure.
Remove the @BinaryTasks methods and replace them with:
@Mutate
void createBinaryTasks( ModelMap<Task> tasks, ModelMap<MyCmp> cmps )
{
cmps.each { cmp ->
def binOne = cmp.binaries.binaryOne
def binOneTaskName = binOne.tasks.taskName( 'generate' )
def binTwo = cmp.binaries.binaryTwo
def binTwoTaskName = binTwo.tasks.taskName( 'generate' )
tasks.create( binOneTaskName ) {
outputs.file binOne.file
doLast {
logger.lifecycle( "Building ${binOne.file}." )
binOne.file.parentFile.mkdirs()
binOne.file.text = binOne.content
}
}
def binOneTask = tasks.get( binOneTaskName )
binOne.tasks.add( binOneTask )
binOne.builtBy( binOneTask )
tasks.create( binTwoTaskName ) {
inputs.file binOneTask
outputs.file binTwo.file
doLast {
logger.lifecycle( "Building ${binTwo.file}." )
binTwo.file.parentFile.mkdirs()
binTwo.file.text = binOne.content + inputs.files.collect { it.text }.join( '\n' )
}
}
def binTwoTask = tasks.get( binTwoTaskName )
binTwo.tasks.add( binTwoTask )
binTwo.builtBy( binTwoTask )
}
}