问题描述
如果一个插件定义了一系列的任务,是否有可能在它们中注入一个依赖关系,以便在执行插件定义的任务之前调用依赖关系?
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?
native-artifacts插件定义了buildNar(和buildNarxxx,其中xxx是平台配置)任务。它还定义了extractNarDepsxxx(其中xxx是要构建的Nar的平台配置)。 extractNarDeps不会在构建器之前调用,因此构建失败,因为在尝试构建之前,不需要依赖关系下载。
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.
如何将extractNarDepsxxx作为依赖关系注入buildNarxxx?
How do I inject extractNarDepsxxx as a dependency into buildNarxxx?
推荐答案
确定。请考虑以下示例:
Ok. Consider the following example:
apply plugin: 'java'
task someTask
task anotherTask
tasks.classes.mustRunAfter(anotherTask)
tasks.build.dependsOn(someTask)
有一个插件应用 java
和两个自定义任务 someTask
和 anotherTask
。
There's a single plugin applied java
and two custom tasks someTask
and anotherTask
.
任务 build
(取自 java
插件) code> dependsOn someTask
。这意味着当您运行 gradle build
时,此任务将被执行。
Task build
(taken from java
plugin) dependsOn
someTask
. It means that when You run gradle build
this task will be executed.
任务课程
mustRunAfter
anotherTask
。所以当你输入 gradle build anotherTask
, anotherTask
将在 build
。
Task classes
mustRunAfter
anotherTask
. So when You type gradle build anotherTask
, anotherTask
will run before build
.
尝试一下。需要时再询问。
Try it. An ask further questions when needed.
这篇关于Gradle:如何将任务依赖项注入到插件定义的任务中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!