Add task dependency to existing Gradle task

This should work:

apply plugin: 'idea'
task blah{
  // do something
}
tasks.idea.dependsOn(blah)

Maybe my working example would be useful - fragments of build.gradle: (gradle version's 1.6)

ear {

    doFirst {
        tasks.buildWar.execute();
    }

    ...

}

task deployProj <<{
    tasks.ear.execute()
    tasks.copyEar.execute()
    tasks.copyJar.execute()
}

task buildWar(type: GradleBuild) {
    buildFile = 'mysubproject/build.gradle'
    tasks = ['war']
}

task copyEar(type: Copy) {
    from earPath
    into "$System.env.JBOSS_HOME" + deploymentPath
}

task copyJar(type: Copy) {
    from jarPath
    into libPath
}

copyEar.mustRunAfter 'ear'
copyJar.mustRunAfter 'ear'