在Gradle的另一个项目中引用任务的输出 [英] Referencing the outputs of a task in another project in Gradle
问题描述
请考虑以下设置
rootProject
|--projectA
|--projectB
在projectB
中有一个任务taskB
,我希望在projectA
中的复制任务taskA
中引用该任务的输出.例如,taskA
可能类似于:
There is a task taskB
in projectB
and I would like the reference the outputs of that task in a copy task taskA
in projectA
. For example, taskA
might look something like:
task taskA(type: Copy) {
dependsOn ':projectB:taskB'
from ':projectB:taskB.outputs'
into 'someFolder'
}
当然,上面的示例实际上不起作用.虽然可以将任务称为:projectB:taskB
作为依赖项,但:projectB:taskB.outputs
似乎对Gradle毫无意义.我尝试阅读Gradle文档,但没有找到任何引用我正在尝试做的事情.
Of course the above example doesn't actually work. While it's okay to reference the task as :projectB:taskB
as a dependency, :projectB:taskB.outputs
doesn't seem to mean anything to Gradle. I've tried reading through the Gradle docs but didn't find anything that referenced what I'm trying to do.
推荐答案
projectA build.gradle应该是:
projectA build.gradle should be:
evaluationDependsOn(':projectB')
task taskA(type:Copy, dependsOn:':projectB:taskB'){
from tasks.getByPath(':projectB:taskB').outputs
into 'someFolder'
}
这篇关于在Gradle的另一个项目中引用任务的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!