I’m trying to make my project more scalable by building “composite” tasks from other tasks. The problem is I cant seem to set fields on tasks created with project.task programatically (there must be a way).
The SimpleInstall task needs to configure the Download.srcUrl and Download.destFile from its constructor (see “TODO” below).
class Download extends DefaultTask {
@Input
String srcUrl
@OutputFile
File destFile
@TaskAction
void download() {
ant.get(src: srcUrl, dest: destFile)
}
}
class SimpleInstall extends DefaultTask {
SimpleInstall() {
def download = project.task('Download'){
//TODO - how to set the @Input Download.srcUrl property ???
// this doesn't work
srcUrl = "test"
}
this.dependsOn(download)
}
@TaskAction
def install() {
}
}
Thanks Peter. I considered adding an extenstion that bundled the required input so the task defined from the plugin would have everything it needs to initialize the dependent tasks but I really need a way for users to call it from their build.gradle multiple times with different input and add their own customizations rather than just calling the task from the command line and having the plugin do everything. Is there a best practice here? I’m starting to think it might be better to compose gradle incremental tasks from ant tasks and use ant dependency management to track if input/outputs.