Composite builds including composite builds with the same name

A project I am working on, has lots of individual repositories that are independant gradle projects(“modules”) with function, for example “Analytics”, “Storage”, “Networking”, etc.
They all work independently via their gradle scripts, but they all depend on a common composite build called kmp-scripts which is the same in all the projects.

The structure is like this for each ‘module’

  • projectFolder/
    – kmp-scripts
    – shared
  • build.gradle.kts
  • settings.gradle.kts

Where in the settings.gradle.kts we have

This all works fine individually, but because we have lots of individual modules, it would be nice to have a single project that couples everything together, so that when a change is made locally i can check easily by running a build on all the modules.
So i created a gradle project that has git submodules of all the modules.

The structure is like this

  • MegaProjectFolder/
    – Analytics/
    – Networking/
    – Storage/

Where the settings.gradle.kts has the following

The problem is, because they all includeBuild kmp-scripts, i get the following error:
Included build
MegaProjectFolder/Analytics/kmp-scripts has build path :kmp-scripts which is the same as included build MegaProjectFolder/Storage/kmp-scripts

I tried a few alternative solutions, one which was to move the kmp-scripts folder into the root of the mega project but then my modules cannot find the plugin(kmp-scripts) are used as a plugin.

Sorry for essay, its a tricky one, and one i cannot easily make a public repo for. It has me stumped, as i thought when you add a project as a composite build, then it would be evaluated independantly.

The easiest solution is to upgrade Gradle.
In 8.0 this situation was improved and should work as expected.

If you cannot upgrade, then do in MegaProjectFolder/settings.gradle.kts this:

includeBuild("Analytics/kmp-scripts") {
    name = "kmp-scripts-analytics"
includeBuild("Networking/kmp-scripts") {
    name = "kmp-scripts-networking"
includeBuild("Storage/kmp-scripts") {
    name = "kmp-scripts-torage"

then it should also work properly.

1 Like

let me check if gradle upgrade works

1 Like

@Vampire thanks for the help, in the end due to another plugin having an issue with gradle 8, i opted to go down the alternative route by doing the includeBuild(“moduleName/kmp-scripts”) this worked a treat, thanks.

1 Like