Multi-project build runs task for all projects instead of just current project (gradle 2.1)


in our gradle build environment, we have different projects in independent directories. I defined all projects and their directories in settings.gradle. Running on Gradle 2.0, the build was running fine. That is, running from a subproject directory, only this subproject and all dependencies were built. Starting with Gradle 2.1 (and also current 2.2 nightly), running gradle with some task (e.g. compileJava) from a subproject directory leads to the task with this name being run for all projects. Is this change in behaviour considered a bug or what can I do to get the old behaviour back?

My Setup: I declare all projects in settings.gradle and run gradle with “-c /absolutePathATo/gradleSettings/settings.gradle”. The build logic is defined in a root project. I could reproduce the issue with the following (minimal) gradle files.


include ':proj1', ':proj2'
project(':proj2').projectDir = new File("/absolutePathDTo/gradleproj2")
project(':proj1').projectDir = new File("/absolutePathCTo/gradleproj1")
//project(':proj1:sub').projectDir = new File("/absolutePathETo/gradleproj1sub")
  rootProject.projectDir = new File("/absolutePathBTo//gradleroot")


subprojects {
 apply plugin: 'java'

/absolutePathCTo/gradleproj1/build.gradle is empty *


dependencies {
    compile project(':proj1')

On Gradle 2.0, running “gradle -c /absolutePathTo/gradle/gradlesettings/settings.gradle compileJava” from /absolutePathTo/gradle/gradleproj1 will lead to only proj1 being built, while on Gradle 2.1 all projects will be built.

Thank you in advance, Thomas

I’m still very much trying to find a solution. We’re in the process of evaluating to switch from ant to gradle. Since I cannot change our directory structure, I’m stuck with this issue.

Is there any other way to setup a multi-project build with a completely custom directory structure which still works in gradle 2.1 and newer? Or is this change in behavior from gradle 2.0 to 2.1 considered a bug and will be fixed?

Hi Thomas,

Sorry for the late response. This looks like a regression introduced when fixing GRADLE-3086. I have raised GRADLE-3187 for the issue you’re seeing.

In the meantime please add ‘-p .’ when executing Gradle as a workaround to explicitly tell it that you want to execute the command relative to the project in the current directory.

Hello Marcin,

thank you. Adding “-p .” works fine for me until the issue is fixed.