罗路遥
罗路遥

Reputation: 185

How to insert a custom task in gradle

How to define a custom task in gradle, and declare it's dependencies?

In Android Studio project I need to inject a custom task between processDebugManifest and processDebugResources.

This tasks are part of gradle assemble command.

~ gradle assemble

:app:preBuild UP-TO-DATE

:app:preDebugBuild UP-TO-DATE

:app:checkDebugManifest

.......

:app:processDebugManifest UP-TO-DATE

:app:processDebugResources UP-TO-DATE

:app:packageRelease UP-TO-DATE

:app:assembleRelease UP-TO-DATE

:app:assemble UP-TO-DATE

BUILD SUCCESSFUL

Total time: 7.628 secs

Upvotes: 0

Views: 2121

Answers (2)

罗路遥
罗路遥

Reputation: 185

Thank you for all help.

Maybe I I don't have described the problem clearly.

But for android stdio project,you will write a file - 'build.gradle'

And this file will include a plugin - 'com.android.application'

I want to know that I would like to write a task,and this task is adding as a dependency to the existing one in the plugin.

But,I got my answer in a book.

You can see the following example.

  android.applicationVariants.all { variant ->
    if (variant.install) {
        tasks.create(name: "run${variant.name.capitalize()}", 
        dependsOn: variant.install) {
           description "Installs  and runs the main launcher activity."
   }
}

Upvotes: 1

Seagull
Seagull

Reputation: 13859

You can see details in Gradle documentation, section 17.4. Adding dependencies to a task.

Here is an example from documentation, defining custom task, and adding it as a dependency to existing one.

task taskY << {
    println 'taskY'
}

taskX.dependsOn taskY

Upvotes: 1

Related Questions