Perform Android build tasks in custom tasks

I wanted to delete the project makefile and write some nice gradle tasks. I need to complete the following tasks in the following order:

  • Clean
  • Increment version
  • Build
  • Download

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

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

The order of execution was not as large as I think clean was started after build . And binrayUpload worked without taste ( release ). I also tried using dependsOn without success (the order does not work).

I could not find in the gradle doc document how to do this correctly. When executed in the correct order, everything works fine from the CLI.

+5
source share
2 answers

Use mustRunAfter or finalizedBy to control finer order:

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

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' } 

There was a way out

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

and executed ./gradlew bintryUpload

0
source

Source: https://habr.com/ru/post/1240012/


All Articles