[英]Gradle: Call root-task with recursive execution from subprojects
If i have a gradle multi-project like this 如果我有这样的gradle多项目
RootProject
+-- SubProjectA
+-- SubProjectB
and every project has a task 'foo', i can call it on the root project 每个项目都有一个任务“ foo”,我可以在根项目上调用它
RootProject>gradle foo
and it also gets executed for the subprojects 并且也为子项目执行
:foo
:SubProjectA:foo
:SubProjectB:foo
But if i call task ':foo' from a Subproject 但是如果我从子项目中调用任务':foo'
RootProject\SubProjectA>gradle :foo
only the task on root project gets executed 仅执行根项目上的任务
:foo
but not the 'foo' tasks on the subprojects. 但不是子项目上的“ foo”任务。
Is there a way to call 'foo' on all projects while being in a subproject? 在子项目中时,是否可以在所有项目上调用“ foo”? I'm asking this because i am using the gradle eclipse plug-in and there i only have access to the subprojects, ie the projects that i see in eclipse. 我之所以这样问是因为我正在使用gradle eclipse插件,并且在那里我只能访问子项目,即我在eclipse中看到的项目。
By the way: The (somewhat hacky) solution i came up with so far 顺便说一句:到目前为止,我想出了(有些hacky)解决方案
task fooAll(type:Exec) {
workingDir '..'
commandLine 'cmd', '/c', 'gradle foo'
}
Resolving of task names (eg foo
) to tasks is a function of the start directory , which defaults to the current directory. 将任务名称 (例如foo
)解析为任务是start目录的功能,默认情况下为当前目录。 You can change the start directory with the -p
command line option (see gradle --help
). 您可以使用-p
命令行选项更改开始目录(请参阅gradle --help
)。 So you'd have to do something like gradle foo -p ../
. 因此,您必须执行gradle foo -p ../
。
Also importing the root project might be a better way to solve your Eclipse problem. 另外,导入根项目可能是解决Eclipse问题的更好方法。 The Eclipse tooling handles hierarchical directory layouts very well. Eclipse工具可以很好地处理分层目录布局。
PS: :foo
is a task path . PS:: :foo
是任务路径 。 It refers to the task named foo
in the root project ( :
). 它指的是任务命名为foo
根项目( :
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.