Utkarsh Tiwari
Utkarsh Tiwari

Reputation: 145

Run a Gradle plugin task when Gradle build is running (not manually from command line)

There is gradle plugin task that can be run from commandline like this -

$ ./gradlew runThisPlugin

But I want this plugin task to execute when gradle build is running (after I hit 'Run' or 'Rebuild' in Android studio). I am actually trying to eliminate the manual work here.

Is there any way to configure the plugin or gradle to run this task automatically when I build the project instead of running it manually from command line?

Upvotes: 0

Views: 1063

Answers (1)

Damir Alibegovic
Damir Alibegovic

Reputation: 318

From the official documentation:

The default run/debug configuration launches the default project activity and uses the Select Deployment Target dialog for target device selection. If the default settings don't suit your project or module, you can customize the run/debug configuration, or even create a new one, at the project, default, and module levels. To edit a run/debug configuration, select Run > Edit Configurations.

The dialog looks like this: Run configuration dialog

In the bottom right part of the screen, there is a Before launch menu.

Click on the + sign, and select Run Gradle Task

Add new configuration dialog

A Select Gradle Task dialog will appear.

Select Gradle Task dialog

Here select Gradle Project that you want, and Tasks that you want to run.

Click Ok two times and you are done.

Note that you task will be run before the build.

Here is a link to official documentation.

Upvotes: 1

Related Questions