How to avoid circular dependency with conditon

I am writing a custom gradle plugin for Android. I want to create a task that depends on the output of the AGP built-in task and it maybe changes the input of that task so the built-in task must be run again, But this creates circular dependency between tasks.
Scenario:

  • input file of AGP task
  • AGP task run and produces an output
  • MyTask processes this output and changes the input file
  • AGP task run again and produces an output
  • MyTask processes this output and decides no need to change
    build finished.

How can I implement this scenario with Gradle? I can not copy the AGP task or call the action of it from MyTask?

No, you can neither run a task multiple times during one Gradle execution, nor can you “call” a task.
Such situation like you describe sounds like not being a good approach actually and should most probably solved differently.

1 Like