How to call an external gradle script once with all tasks to run from original script

I have two build scripts:
Script A (a multi-project build with 6 sub projects)
Script B (a multi-project build with 20+ sub projects)

The B script drives a third party compilation tool that makes assumptions about being in the root of the overall build. The result is that A & B cannot be included in a single unified multi-project build.

I’ve been asked to tie the scripts together so that a developer can execute the gradle once in the root directory and have everything build.

I figured out one way to do this at a task level:

task clean(type: GradleBuild) {
     buildFile = '../other/build.gradle'
     tasks = ['clean']
}

task build(type: GradleBuild) {
    buildFile = '../other/build.gradle'
    tasks = ['build']
}

task cleanEclipse(type: GradleBuild) {
    buildFile = '../other/build.gradle'
    tasks = ['cleanEclipse']
}

task eclipse(type: GradleBuild) {
    buildFile = '../other/build.gradle'
    tasks = ['eclipse']
}

However, with this structure, the execution takes significantly more time than running the two scripts separately. I figure this is due to the overhead of spinning up a separate external build for each task.

From the A script, I am looking for a way to call the B script just once, passing all of the command line arguments. Ideally, this would mean just one B-script execution.

I am sure this can be done, I’m just not sure how.

4 Likes

If I am understanding you correctly you could call the ‘B’ project with the same task arguments used to run ‘A’.

task buildProjectB(type: GradleBuild) {
    tasks = gradle.startParameter.taskNames
}
2 Likes