Using RuleSource and @BinaryTasks adding task dependencies


(Ethan Hall) #1

I’m playing with the new model and am trying make check depend on a custom task that runs tests. I have a method (createTasks) thats annotated with @BinaryTasks and it currently adds 7 tasks that build depends on. How do I define a task that check depends on using the new model?


(Mark Vieira) #2

You’ll do this with a @Mutate rule.

@Mutate
public void addVerificaitonTask(ModelMap<Task> tasks) {
    Task myTask = tasks.create("mytask");
    tasks.getByName("check").dependsOn(myTask);
}

(Ethan Hall) #3

Thanks for the info. With the new model, should the check tasks be created with the BinaryTasks or make them in an @Mutate method?


(Mark Vieira) #4

The @BinaryTasks annotation should only be used when the Binary is an input to the task. If the task you are creating is independent of any binary then I’d say use a @Mutate rule instead. Really, you can think of @BinaryTasks as simply a @Mutate rule that is executed for every Binary.


(Chris Doré) #5

Hi @mark_vieira,

ModelMap.create has no return value. Is there a recommended approach apart from calling tasks.get/getByName after calling tasks.create?

@Mutate
public void addVerificationTask(ModelMap<Task> tasks) {
    tasks.create("mytask")
    tasks.getByName("check").dependsOn(tasks.getByName("mytask"))
}

(Mark Vieira) #6

The dependsOn() method will also accept a String.

tasks.getByName('check').dependsOn('mytask')