Reputation: 1279
Gradle has the ability to run tasks after other tasks. The syntax is taskY.mustRunAfter taskX. The android gradle plugin says one of the ApplicationVariant tasks it defines is packageApplication.
In my build.gradle I have
taskX.mustRunAfter packageApplication
The error I get is "Could not find property 'packageApplication' on project ':someproject'."
Is it even possible to get access to the packageApplication task? If so is it considered bad practice?
Upvotes: 3
Views: 3733
Reputation: 1279
I found my the answer. rciovati cleared up the confusion around mustRunAfter and that what I was doing was the wrong approach. I ended up converted taskY to a groovy function. Then used the following code:
android.applicationVariants.all { variant ->
// rename apk after we assemble the application
variant.assemble.doLast {
taskY(variant)
}
Upvotes: 8
Reputation: 28063
Please note this sentence from the documentation:
By using 'must run after" ordering rule you can specify that taskB must always run after taskA, whenever both taskA and taskB are scheduled for execution.
This means that
taskX.mustRunAfter packageApplication
doesn't make the taskX
run always after packageApplication
but just if you type:
./gradlew taskX packageApplication
On the other hand, it doesn't define a dependency, that is it doesn't automatically run taskX
task.
To do something, after a task is executed you can use the doLast
closure:
taskX.doLast{ println 'Hello' }
The packageApplication
is a property of the ApplicationVariant
class but not a task. The tasks are package<VariantName>
.
Upvotes: 1