How to add JARs generated by tasks to compile dependencies

I have tried using the method listed here, resulting in the following:

apply plugin: 'com.android.library'

task buildJars(type: Exec) {
    outputs.dir('libs')
    commandLine 'ant' 'buildJars'
}

dependencies {
    compile fileTree(tasks.buildJars.outputs.files.singleFile) {
        builtBy tasks.buildJars
        include '**/*.jar'
    }
}

clean << {
    exec {
        commandLine 'ant' 'clean'
    }
}

It behaves exactly as before - fails the first time, succeeds the second. I think that makes sense, because the only real difference is in the enumeration of the JARs.