Uma*_*ang 14 android gradle android-studio android-gradle-plugin
我有一个包含多个模块的android项目.我试图从其中一个模块运行自定义gradle任务,但每次我在模块以及其他模块中运行任务所有其他gradle任务.我的任务不依赖于任何其他任务.任务 :
task helloTask{
println "Hello task"
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试通过工作室和命令行中的终端窗口运行此任务.
JBi*_*gas 12
Gradle将执行<<
配置阶段未声明的所有任务.如果你想将任务的执行延迟到执行阶段,那么你可以添加<<
在你的 build.gradle
task helloConfiguration { task ->
println "Hello configuration phase task! $task.name"
}
/* Notice the `<<` this denotes to gradle to not execute
* the closure during the configuration phase. Instead
* delay closure's execution till the execution phase.
*/
task helloExecution << { task ->
println "Hello execution phase task! $task.name"
}
helloExecution.dependsOn helloConfiguration
Run Code Online (Sandbox Code Playgroud)
然后在执行helloExecution
任务时我们看到两个运行,确保顺序.接下来,如果我们只想运行配置构建的任务,我们可以根据需要单独执行,并且只运行单个任务.
$ gradle helloExecution
Hello configuration phase task! helloConfiguration
Hello execution phase task! helloExecution
:helloConfiguration UP-TO-DATE
:helloExecution UP-TO-DATE
BUILD SUCCESSFUL
Total time: 0.64 secs
$ gradle helloConfiguration
Hello configuration phase task! helloConfiguration
:helloConfiguration UP-TO-DATE
BUILD SUCCESSFUL
Total time: 0.784 secs
Run Code Online (Sandbox Code Playgroud)
即使没有提供任务,在配置阶段运行的任务也将始终执行,这是我期望您看到的行为.所以给出上面的例子.注意配置任务已运行但未执行.
$ gradle
Hello configuration phase task! helloConfiguration
:help
Welcome to Gradle 2.10.
To run a build, run gradle <task> ...
To see a list of available tasks, run gradle tasks
To see a list of command-line options, run gradle --help
To see more detail about a task, run gradle help --task <task>
BUILD SUCCESSFUL
Total time: 0.651 secs
Run Code Online (Sandbox Code Playgroud)
因此,如果您在配置阶段运行了5个任务,那么无论命令行args尝试为执行阶段的目标调用哪个任务,您都会看到所有任务都执行.
在Android Studio中调出Gradle视图(Android Studio窗口的右上角)
按Run Gradle Task(圆形按钮)。
从模块列表中选择包含build.gradle的模块,然后从任务列表中选择task。
同样,在Gradle视图树中YourModule/Tasks/other
,除非group
明确为任务指定,否则您的任务将显示在下方。
小智 5
您可以使用运行配置来实现相同的目的。参考: https: //developer.android.com/studio/run/rundebugconfig.html
转到运行 -> 编辑配置 -> 单击 + 添加新配置 -> 从出现的列表中选择 Gradle。最后选择应用程序,然后输入您要运行的任务。Android Studio 甚至会提供自动完成功能。
稍后,可以直接在“运行”菜单中选择运行该任务。
归档时间: |
|
查看次数: |
16476 次 |
最近记录: |