Extra side-effects of Project.getTasksByName()?

You could just change your logic to

allprojects {
   tasks.matching { it.name == 'foo' }.all {
      // logic goes here
   } 
} 

Then you wouldn’t need an afterEvaluate{...} closure or evaluationDependsOnX. See here for related topic