How to invoke ant target from with a task?

I would like to do something like

ant.importBuild 'build-foo.xml'
  compile {
    inputs.files inputFiles
    outputs.dir "$projectDir/build/reporting/dist"
          doLast {
        // invoke an ant target here
    }
}

Is this possible?

You could do the following:

compile.finalizedBy yourAntTarget

That works but the ant target is always called. The inputs and outputs should prevent the compile task from executing when it doesn’t need to. So I need the ant target to only be called when the compile task is executed.