1

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'
}

1 Answers1

1

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 (:).

Peter Niederwieser
  • 121,412
  • 21
  • 324
  • 259
  • I importet the root project into eclipse (didn't know that this is possible, but it is), made it a gradle project and now i can call tasks on the root project. Unfortunately the gradle eclipse plugin calls the tasks in a qualified way, i.e. it calls ':foo' instead of 'foo'. So only task 'foo' on the root projects gets executed. – Christoph Baumann Mar 28 '13 at 16:26
  • I was wondering if the plugin supports task names already, but your question sounded as if it did. Do you have the latest version? – Peter Niederwieser Mar 28 '13 at 16:32
  • My plug-in version is 3.1.0.201210040512. And according to eclipse update and the marketplace client there is no update. So far i haven't found a way to change the Gradle Launch Configurations to use task names instead of paths. – Christoph Baumann Mar 28 '13 at 16:49
  • From what I can tell, it isn't supported yet, and you have to select the tasks individually. – Peter Niederwieser Mar 28 '13 at 16:52