在android studio中执行自定义独立gradle任务

在android studio中执行自定义独立gradle任务,第1张

概述我有一个包含多个模块的android项目.我试图从其中一个模块运行自定义gradle任务,但每次我在模块以及其他模块中运行任务所有其他gradle任务.我的任务不依赖于任何其他任务.任务:taskhelloTask{println"Hellotask"}我已经尝试通过工作室和命令行中的终端窗口运行此任务.

我有一个包含多个模块的android项目.我试图从其中一个模块运行自定义gradle任务,但每次我在模块以及其他模块中运行任务所有其他gradle任务.我的任务不依赖于任何其他任务.任务 :

task helloTask{   println "Hello task"}

我已经尝试通过工作室和命令行中的终端窗口运行此任务.

解决方法:

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

然后在执行helloExecution任务时,我们看到两个运行,确保顺序.接下来,如果我们只想运行配置构建的任务,我们可以根据需要单独执行,并且只运行单个任务.

$gradle helloExecutionHello configuration phase task! helloConfigurationHello execution phase task! helloExecution:helloConfiguration UP-TO-DATE:helloExecution UP-TO-DATEBUILD SUCCESSFulTotal time: 0.64 secs$gradle helloConfigurationHello configuration phase task! helloConfiguration:helloConfiguration UP-TO-DATEBUILD SUCCESSFulTotal time: 0.784 secs

即使没有提供任务,在配置阶段运行的任务也将始终执行,这是我期望您看到的行为.所以给出上面的例子.注意配置任务已运行但未执行.

$gradleHello configuration phase task! helloConfiguration:helpWelcome to Gradle 2.10.To run a build, run gradle <task> ...To see a List of available tasks, run gradle tasksTo see a List of command-line options, run gradle --helpTo see more detail about a task, run gradle help --task <task>BUILD SUCCESSFulTotal time: 0.651 secs

因此,如果您有5个在配置阶段运行的任务,那么您将看到所有这些任务都执行,而不管命令行args尝试为执行阶段的目标调用的任务.

总结

以上是内存溢出为你收集整理的在android studio中执行自定义独立gradle任务全部内容,希望文章能够帮你解决在android studio中执行自定义独立gradle任务所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1097581.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存