I can build both SubProjects (C & java) individually from respective subproject’s build file. Now I want to build java and native subprojects separately (as individual tasks) from the root folder, how can I do that? What will be the content of setting.gradle file of project A?
Thank you for your response. But in section 10.5 it is mention that composite builds are not supported for Native Builds. I am trying to create two separate tasks for java and native in root projects with corresponding subprojects. I am not sure whether this is right approach or not.
It is correct that you would only have one settings.gradle for a single multi-project build (no composite). It should like this for the above structure:
rootProject.name = 'A'
include 'Java'
include 'Java:J1'
include 'Java:J2'
include 'Native'
include 'Native:C1'
include 'Native:C2'
If you are in the root build, gradle build would build everything. If you’re wanting to build just one subproject tree, use the path when specifying the task. For the Java subprojects, use gradle :Java:build. For the Native project, use gradle :Native:build. The expectation is that the Java project build task is wired up to build everything in the subprojects already. If you want to create a root project task like buildJavaProjects or buildNativeProjects, you can wire up a dependency in the A root project:
task buildJavaSubProjects(dependsOn ':Java:build') {
group = 'Build'
description = 'Builds all Java projects.'
}
Alternatively, if you want the behavior of calling only J1 and J2 project build tasks (without wiring up anything special in Java ), you can use:
task buildJavaSubProjects {
group = 'Build'
description = 'Builds all Java projects.'
project(':Java').subprojects { dependsOn "${it.path}:build" }
}
Replace project(':Java').subprojects with project(':Java').allprojects if you want build to run on Java, J1, and J2 without doing anything special in Java (same as running gradle build from a project normally).
The same procedure would apply on the Native side.