在Gradle的另一个项目中引用任务的输出 [英] Referencing the outputs of a task in another project in Gradle

查看:193
本文介绍了在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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆