Custom compilation script on legacy C++ project and modules dependencies

Hello,
I’m trying to gradually migrate a legacy C++ project to Gradle. This project uses an overly complicated system of bash scripts to compile the various modules and put the results in some common directories (for headers, libs and executables).

I would like, as a starting point, to use the preexisting build scripts (I would migrate them to Gradle in a later moment) and use Gradle to manage dependencies between the project’s submodules.

I have setup a settings.gradle file in the root directory with the list of modules and then wrote this build.gradle file:

allprojects {
    task build {
        exec {
            commandLine 'sh', "${project.name}.sh", '32', 'all'
        }
    }
}

It works! But I’m not able to add dependencies, they are simply ignored and the modules are compiled in alphabetical order. I suppose that this happens because I’m not using any plugin.

Is there any way to achieve what I want to do?

It was frustrating, but in the end I was able to achieve what I wanted.

settings.gradle:

rootDir.eachDir { f ->
if(!f.getName().startsWith(".") &&
       !f.getName().startsWith("include") &&
       !f.getName().startsWith("lib") &&
       !f.getName().startsWith("lib64") &&
       !f.getName().startsWith("exe") &&
       !f.getName().startsWith("i686") &&
       !f.getName().startsWith("x86_64") ) {
		include f.getName()
    }
}

This will include all the subdirectories as modules

root build.gradle:

defaultTasks 'build'

allprojects {
    task build {
        doLast {
            exec {
                commandLine 'sh', "${project.name}.sh", '32', 'all'
            }
        }
    }
}

This will invoke out custom build script for every submodule. Note that I had to add an empty project_name.sh to the root project, otherwise Gradle was complaining that the file was missing. I don’t know if there’s a setup to tell him to not try to call the build script in the root directory, I still have to research this.

Example of a submodule build.gradle:

build {
    dependsOn ":lib1:build"
    dependsOn ":lib2:build"
    dependsOn ":lib6:build"
}

This defines the submodules tat are dependencies of the current module.

And that’s it!