Running one task in a loop inside another. Migrating from Ant

I can’t see why you need a jar task and a copy task. You could do something like.

task jarAll {}
file(ClassesDir).listFiles().findAll { it.directory }.each { classDir ->
   def classFolder = classDir.name
   Task jarTask = tasks.create("${classFolder}Jar", Jar) {
      from classDir
      include '**/*.class'
   } 
   jarAll.dependsOn jarTask 
} 

This requires that the class dirs are available at configuration time which is probably not the case. Do you know the class dirs by another means? Ie is there another way to know the class dirs instead of file(ClassesDir).listFiles()