Expected behaviour of GradleBuild task

What is the expected behaviour of the GradleBuild task? Is it supposed to execute another Gradle script and load it into the memory space of the current project or is it to execute is completly independently?

For instance let’s say I have


And root/build/gradle contains

task buildAnother( type : GradleBuild ) {
  dir 'subdir'
  buildFile 'subdir/build.gradle'
  tasks ['foo']
  startParameter gradle.startParameter

and root/settings.gradle is empty (i.e. subdir is not part of the project tree of root). Also subdir/settings.gradle exists, therefore normally running subdir/build.gradle will not search up the tree.

If I run gradle buildAnother, it seems to be recursively loading and reconfiguring the project in root. It never gets to executing the buildscript in subdir.

I’d say that’s “expected but not obvious”.

When you set startParameter = gradle.startParameter, you’re getting all of the properties used for the current build (project directory, task list, etc). You probably want to do something like:

task buildAnother(type: GradleBuild) {
   startParameter = gradle.startParameter.newBuild()
   dir = file("subdir")
   tasks = [ "foo" ]

You’ll get a copy of all the settings from the outer build (–parallel, --offline, etc), but it’ll use subdir as the current directory and find projects there.

We don’t currently fork a separate JVM for this, so it appears to just be another build running inside the same JVM. We’ll eventually have a GradleBuild task that uses the tooling API instead of going through the internal mechanisms which will allow for separate JVMs.

Mmm… when I add newBuild() I only get the Gradle help message displayed. (But thankfully at least no endless loop).