As you have seen in documentation, there are three phases: Initialization, Configuration and Execution. Each step is traversed from root project down to subprojects for multi project builds. The afterEvaluate is useful in the root gradle file of a multi project build when you want to configure specific items based on the configuration made in subprojects.
Say you want to add a task for all subprojects that have a specific plugin defined. If you add to your root project:
subprojects {subProject ->
if ( subProject.plugins.hasPlugin('myplugin')){
subProject.task('newTask')<<{
println "This is a new task"
}
}
}
This task will never be added since the root project is configured before the subprojects.
Adding afterEvaluate will solve this for you:
subprojects {subProject ->
afterEvaluate{
if ( subProject.plugins.hasPlugin('myplugin')){
subProject.task('newTask')<<{
println "This is a new task"
}
}
}
}