Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 975
Hugo Gresse Avatar asked Jan 06 '16 16:01

Hugo Gresse


People also ask

How do I run a custom Gradle task?

Go to Run -> Edit Configurations -> Click on + to add a new configuration -> Select Gradle from the list that comes up. Finally select the app, and type in the task that you want to run. Android Studio will even provide autocomplete for the same.

Does Gradle build run all tasks?

You can execute multiple tasks from a single build file. Gradle can handle the build file using gradle command. This command will compile each task in such an order that they are listed and execute each task along with the dependencies using different options.

What is task in build Gradle?

The work that Gradle can do on a project is defined by one or more tasks. A task represents some atomic piece of work which a build performs. This might be compiling some classes, creating a JAR, generating Javadoc, or publishing some archives to a repository.


1 Answers

Use mustRunAfter, or finalizedBy for finer order control:

task releaseMajor (dependsOn: ['clean', 'build', 'incrementVersion', 'bintrayUpload'])
build.mustRunAfter clean
incrementVersion.mustRunAfter build
bintrayUpload.mustRunAfter incrementVersion
like image 58
RaGe Avatar answered Oct 02 '22 11:10

RaGe