Call doFirst in task constructor

I’m trying to add an action to my task with doFirst, but for some reason the action isn’t executing (it is added though). I’m calling doFirst in the constructor of the task like this: public Mxmlc() {

doFirst(new ValidateMxmlcTaskPropertiesAction()) }

The action class: class ValidateMxmlcTaskPropertiesAction implements Action {

void execute(Mxmlc task) {

} }

But when I do the following it is executed (but I want to add it in the constructor): project.tasks.add(Tasks.COMPILE_TASK_NAME, compileClass) project.compile.doFirst(new ValidateMxmlcTaskPropertiesAction())

any ideas on why this doesn’t work? Thanks :slight_smile:

any ideas?

Hello yennick, I think the problem is, that the validationAction is executed AFTER your main action. The reason for that is: 1. the task is instantiated using the ctor. 2. doFirst in your ctor adds an action to the tasks action list. 3. the task main action is added via doFirst to the tasks action list (“in front” of your custom doFirst action)

A workaround would be to instantiate your CustomAction directly in the main action of your task. I’ve appended a snippet, that shows a simple example of this:

class ValidateMxmlcTaskPropertiesAction implements Action{
 public void execute(Object object){
  println "do validation Action"
  class Mxmlc extends DefaultTask{
  public void doit(){
  new ValidateMxmlcTaskPropertiesAction().execute(this)
  println "do main action"
  task mxmlc(type:Mxmlc)

Thanks, that works! :slight_smile: