How to invoke subtasks of subprojects in the parent build.gradle?


(Bálint Kriván) #1

I have a project like this: / - parent

|- subproject1

|- subproject2

Each of the subprojects has a task ‘installWithConfig’ which depends on ‘installApp’ task (from application plugin) and the only thing it does is to add some files to the ‘bin/’ directory.

So running gradle in the subprojects with ‘gradle installWithConfig’ produces good stuff in ‘build/install/’. I want to make an “ubertask” (named ‘uberBuild’) in the parent build.gradle which copies the contents together.

My problems: * I can’t write this: ‘task uberBuild(dependsOn: project(’:subproject1’).installWithConfig) << { … }’ cause gradle says ‘installWithConfig’ is not a valid property of the project * When I invoke it manually with ‘project(’:BIGlossary’).installWithConfig.execute()’ – it only does the job defined in the actual task and not the dependencies (e.g.: ‘installApp’ nor its further dependencies)

Please help me to provide a valid way to achieve something like this in Gradle. Thanks!


(Attila Kelemen) #2

Try writing ‘dependsOn: “:subproject1:installWithConfig”’ instead of ‘dependsOn: project(’:subproject1’).installWithConfig’.

EDIT: Quotes should be included as well.


(Bálint Kriván) #3

Thanks, it works like a charm!


(Bálint Kriván) #4

And is it possible to reach properties of these tasks? so I can I use dot notation for further properties?


(Attila Kelemen) #5

No, but you can use your original approach in the ‘doLast’ (’<<’). Or in some other way you have to ensure that that task has been configured when you are trying to access its properties.


(Bálint Kriván) #6

yes, thanks. I’ve just thought the same solution and it works, the problem was only during configuration but that was solved with your help. Thanks again!