Hugo Gresse
Hugo Gresse

Reputation: 17909

Execute android build tasks in custom tasks

I wanted to remove the project makefile and write some nice gradle tasks. I need to execute the following tasks, in this order:

  1. Clean
  2. Increment version
  3. Build
  4. Upload

#1, #3 and #4 are tasks from android and plugin (bintray) while #2 is a custom task. Here is what I have so far:

task releaseMajor {
    doLast {
        clean.execute()
        build.execute()
        incrementVersion.execute()
        bintrayUpload.execute()
    }
}

The run order was not so great as I think clean was run after build. And binrayUpload was running without flavor (release). I've also tried to use dependsOn without success (order not working).

I couldn't find in Gradle doc how to do this properly. When execute in the right order, from CLI, everything works perfectly.

Upvotes: 6

Views: 1409

Answers (2)

prijupaul
prijupaul

Reputation: 2086

Tried this

task clean {
    println 'clean task executing'
}
task incrementVersion (dependsOn:"clean"){
    println 'incrementVersion task executing'
}
task building (dependsOn:"incrementVersion"){
    println 'build task executing'
}
task bintrayUpload (dependsOn:"building") {
    println 'bintrayUpload task executing'
}

The output was

clean task executing
incrementVersion task executing
build task executing
bintrayUpload task executing

and executed ./gradlew bintryUpload

Upvotes: 0

RaGe
RaGe

Reputation: 23795

Use mustRunAfter, or finalizedBy for finer order control:

task releaseMajor (dependsOn: ['clean', 'build', 'incrementVersion', 'bintrayUpload'])
build.mustRunAfter clean
incrementVersion.mustRunAfter build
bintrayUpload.mustRunAfter incrementVersion

Upvotes: 2

Related Questions