How to invoke subproject's build task in root project's task?


(Geekids) #1

hi team,

Here is my project detail:

rootproject:
----build.gradle
----settings.gradle
----subproject1.gradle
----subproject2.gradle

subproject1
subproject2

I am trying to start my gradle build in jenkins, and I want spcific the projects I want to build on jenkins UI. Here is the UI:

I can get the parameters I set on the UI, then I want to use the parameters to invoke the specified subproject’s build task.

I wrote a task in rootproject’s build.gradle

task buildAll << {
def isBuildAEar = project.hasProperty(‘build_AEAR’) ? project.property(‘build_AEAR’): false;
if(isBuildAEar == ‘true’) {
// then I want to invoke the AEar’s build task here…
}
}

I tried different solutions but all failed, like:
project(‘AEar’).tasks[‘build’].execute
or use exec task to exceute gradle :AEar:build etc

Could anyone can help to give any adivce? Thank you very much.

Wales
2016-09-28


(Geekids) #2

Greate news! I did it.

I refine the task in rootproject’s build.gradle

task buildAll(type:GradleBuild) {
def isBuildAEar = project.hasProperty(‘build_AEAR’) ? project.property(‘build_AEAR’): false;
if(isBuildAEar == ‘true’) {
tasks = [’:AEar:build’];
}
}

The key info is define the task as GradleBuild and then specifiy the tasks as the subprojects’ build task

the tasks can be set as List, example,

List selectedProjects = new ArrayList();
selectedProjects.add(’:subproject1:build’);
selectedProjects.add(’:subproject2:build’);
selectedProjects.add(’:subproject3:build’);

tasks = selectedProjects