【发布时间】:2018-03-31 18:13:30
【问题描述】:
我有一个这样的多项目构建
main
|_build.gradle
|_settings.gradle
|_examples
|_|_build.gradle
|_|_simple-project
|_|_|_build.gradle
settings.gradle
rootProject.name = 'main'
include 'examples'
include 'examples:simple-project'
现在在examples 项目build.gradle 中,我已经为所有子项目声明了一个任务,如下所示:
subprojects {
task hello(group: 'example') {
doLast {
println "${it.project.name}: I am part of example"
}
}
}
当我运行gradle tasks --all 时,我得到类似于以下(以及其他)的输出:
Example tasks
-------------
examples:simple-project:hello
现在我尝试像这样为simple-project 运行该任务
gradle -p examples/simple-project hello
我得到的输出是:
FAILURE:构建失败并出现异常。
出了什么问题:在项目 ':examples:simple-project' 中找不到任务 'hello'。一些候选人是:“帮助”。
尝试:运行 gradle 任务以获取可用任务列表。使用 --stacktrace 选项运行以获取堆栈跟踪。使用 --info 或 --debug 选项运行以获得更多日志输出。运行 --scan 以获得完整的见解。
通过https://help.gradle.org获得更多帮助
0 秒内构建失败
我做错了什么?在子项目中运行任务的正确方法是什么?
编辑
如果我改为运行它
gradle -p examples hello
那么这也会运行子项目任务 (hello)
> 任务:examples:simple-aspect-project:hello
简单方面的项目:我是一个例子
我不想要这个。我希望能够为我想要的子项目运行任务,而不是一次全部运行。
【问题讨论】:
标签: gradle build.gradle gradle-task