execute task before android gradle build?
是否有可能在调用之前就使执行任务更容易
1 | gradle build |
像预编译的东西。 有人请帮忙。 是这样的事情,怎么办?
您可以通过以下方式进行操作:
1 2 3 4 5 6 7 | task build << { println 'build' } task preBuild << { println 'do it before build' } build.dependsOn preBuild |
由于该任务,
如果要在配置阶段中运行
1 2 3 4 5 6 | task build << { println 'build' } build.doFirst { println 'do it before build' } |
有关gradle构建生命周期的更多信息,请参见http://www.gradle.org/docs/current/userguide/build_lifecycle.html。
对于那些想知道如何在Android项目中执行此操作的人,这对我有用:
1 2 3 4 | task myTask << { println"here's a task" } preBuild.dependsOn myTask |
还有另一种方法
1 2 3 4 5 6 7 | task myTask << { println"here's a task" } tasks.whenTaskAdded { task -> if (task.name == 'assembleDebug') { task.dependsOn myTask } |
在Gradle 5.4.x中
1 2 3 4 5 6 7 8 | // File: app/build.gradle // See: https://docs.gradle.org/current/dsl/org.gradle.api.tasks.Exec.html task ruby(type:Exec) { workingDir '../' executable = '/usr/bin/env' args = ["ruby","--version"] } preBuild.dependsOn ruby |
如果已经定义了要运行的任务(例如
1 | build.dependsOn publishToMavenLocal |