We are writing a custom task. We would like to do some initialization work during the loading phase of the task (Specifically we would like to make this task a dependend of other tasks automatically).
What we do know is this:
class SomeCodeGenerationTask extends DefaultTask {
@Input
def schema
def setSchema(def schema) {
// We know this code is called in initialization
this.schema = schema
initCodeGeneration()
}
def initCodeGeneration() {
// ...
this.project.tasks.generate.dependsOn this
}
@TaskAction
def generateCode() {
//...
}
}
Ideally, we would do something like this:
class SomeCodeGenerationTask extends DefaultTask {
@Input
def schema
@Initialize
def initCodeGeneration() {
// ...
this.project.tasks.generate.dependsOn this
}
@TaskAction
def generateCode() {
//...
}
}
Is there a way in gradle to this without “calling the init method in the setter” hack?