Question

If i have a gradle multi-project like this

RootProject
+-- SubProjectA
+-- SubProjectB

and every project has a task 'foo', i can call it on the root project

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

RootProject\SubProjectA>gradle :foo

only the task on root project gets executed

:foo

but not the 'foo' tasks on the subprojects.

Is there a way to call 'foo' on all projects while being in a subproject? I'm asking this because i am using the gradle eclipse plug-in and there i only have access to the subprojects, i.e. the projects that i see in eclipse.

By the way: The (somewhat hacky) solution i came up with so far

task fooAll(type:Exec) {
    workingDir '..'
    commandLine 'cmd', '/c', 'gradle foo'
}
Was it helpful?

Solution

Resolving of task names (e.g. foo) to tasks is a function of the start directory, which defaults to the current directory. You can change the start directory with the -p command line option (see gradle --help). So you'd have to do something like gradle foo -p ../.

Also importing the root project might be a better way to solve your Eclipse problem. The Eclipse tooling handles hierarchical directory layouts very well.

PS: :foo is a task path. It refers to the task named foo in the root project (:).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top