Gradle: how do I inject a task dependency into a plugin-defined task?

早过忘川 提交于 2019-12-12 02:49:39

问题


If a plugin defines a series of tasks, is it possible to inject a dependency into these, such that the dependency is called before the plugin-defined task is executed?

The native-artifacts plugin defines buildNar (and buildNarxxx, where xxx is the platform config) tasks. It also defines extractNarDepsxxx (where xxx is the platform config for the Nar to be built). extractNarDeps is not called before builder, so the build fails as required dependencies are not downloaded prior to the attempted build.

How do I inject extractNarDepsxxx as a dependency into buildNarxxx?


回答1:


Ok. Consider the following example:

apply plugin: 'java'

task someTask
task anotherTask

tasks.classes.mustRunAfter(anotherTask)
tasks.build.dependsOn(someTask)

There's a single plugin applied java and two custom tasks someTask and anotherTask.

Task build (taken from java plugin) dependsOn someTask. It means that when You run gradle build this task will be executed.

Task classes mustRunAfter anotherTask. So when You type gradle build anotherTask, anotherTask will run before build.

Try it. An ask further questions when needed.



来源:https://stackoverflow.com/questions/24101044/gradle-how-do-i-inject-a-task-dependency-into-a-plugin-defined-task

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!