Don’t do this. Gradle has a “configuration” phase and an “execution” phase. A doLast {…} closure is running in the “execution” phase and by this time gradle has calculated the TaskGraph so it’s too late to be adding tasks to the model
See build phases