tasks.withType(JavaCompile).findAll doesn't

I have the following task that is of type JavaCompile and I have a list of JavaCompile tasks.

def compileTasks = project.tasks.withType( JavaCompile ).findAll{ task -> ‘compileJsp’ != task.name }

task compileJasperJava(type: JavaCompile)  {
    options.warnings = true
    source = 'build/jasper'
    classpath = compileJava.classpath + project.sourceSets.main.output
    destinationDir = compileJava.destinationDir
    doLast {
      println 'finished precompile compile'
    }
  }
compileTasks.each { compileTask ->
  compileTask.doFirst {
            println "running compileTask with eclipse: " + compileTask.name
  }
}

When I iterate on the compileTasks, the compileJasperJava is not in the list - thoughts? the default compileJava task is part of the list.

Thank you !

TLDR; It’s an issue with the order of execution

project.tasks returns a TaskContainer which extends DomainObjectCollection and Collection

Some methods on the collection (eg withType(Class), matching(Closure) and all(Closure)) return a “live” collection. So regardless of ordering the handler will fire when subsequent tasks are added.

Other methods (eg findAll(Closure) and each(Closure)) are not “live”. So if tasks are added after these statements the closure will not fire again.

So something like the following should catch subsequent tasks added to the project

tasks.withType(JavaCompile).matching {...}.all {...} 

Thank you ! Seems like that was the issue.