Setting up Gradle to build child projects

When your mainProject includes subProjects, and these in turn include more subProjects, and each of these project needs a different Gradle script, you will need to setup your main gradle to include these child projects, and allow each of them to be built according to their own script.

For example, assuming your Project looks like this:

projectRoot/
	bridge/
		api
	 common

And while there are similarities beween the build of the projectRoot and it’s children, there are some differences with bridge, api and common

In order to support this structure gradle files should be added as follows:

projectRoot/
		build.gradle
		gradlew
		settings.gradle
		.
		.
		bridge/
				build-bridge.gradle
				api/
					build-api.gradle
		common/
				build-common.gradle

The settings.gradle controls what subprojects will be included and what is the buildFile

so it should look like this

include 'bridge', ':bridge:api', 'common'

rootProject.children.each { p ->
	p.children.each { i ->
        i.buildFileName = "build-${i.name}.gradle"
    }
}

running ./gradlew build will build the rootProject, bridge, api & common

Senior DevOps Engineer

DevOps Group
Thank you for your interest!

We will contact you as soon as possible.

Send us a message

Oops, something went wrong
Please try again or contact us by email at info@tikalk.com