我有一个像这样的多项目构建
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: Build failed with an exception.
What went wrong: Task 'hello' not found in project ':examples:simple-project'. Some candidates are: 'help'.
Try: Run gradle tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 0s
我究竟做错了什么?在子项目中运行任务的正确方法是什么?
编辑
如果我改为运行此
gradle -p examples hello
然后这还将运行子项目任务(
hello
)> Task :examples:simple-aspect-project:hello
simple-aspect-project: I am an example
我不要这个我希望能够为我想要的子项目运行任务,而不是一次运行所有任务。
最佳答案
一个简单的gradle :examples:simple-project:hello
怎么样
我认为设置-p examples/simple-project
会减小simple-project
项目的范围,并取消了hello
项目中的examples
任务创建。
关于gradle - 在子项目中运行gradle任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49590907/