简体   繁体   中英

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?

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: 运行配置对话框

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

Click on the + sign, and select Run Gradle Task

添加新配置对话框

A Select Gradle Task dialog will appear.

选择Gradle Task对话框

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM