0

I have following structure:

ProjectA -> depends on ProjectB

ProjectB -> depends on ProjectC

compiling projectB everything works:


ProjectB/build.gradle:

dependencies {
  compile project(':ProjectC')
}

ProjectB/settings.gradle:

include ':ProjectC'
project(':ProjectC').projectDir = new File(settingsDir, '../ProjectC')

However, compiling ProjectA it says it can not find ProjectC


ProjectA/build.gradle:

dependencies {
  compile project(':ProjectB')
}

ProjectA/settings.gradle:

include ':ProjectB'
project(':ProjectB').projectDir = new File(settingsDir, '../ProjectB')

This will show following error:

Where: Build file ProjectB\build.gradle

What went wrong:

A problem occurred evaluating project ':ProjectB'.

Project with path ':ProjectC' could not be found in project ':ProjectB'.


I Could only make it work including ProjectC in ProjectA. But this is not what I want.

I also tried to exclude on ProjectA but didnt work

ProjectA/build.gradle:

dependencies {
  compile (project (':ProjectB')) {
    exclude module: ':ProjectC'
  }
}

But shows same error.

How can I fix this?

Mayday
  • 4,680
  • 5
  • 24
  • 58

2 Answers2

1

Multi-Project builds are not cascadable. You can have either one or no settings.gradle file in a multi-project build, but not multiple.

Besides that it is not working as expected, it can even get more confusing if you call Gradle from different directories. Gradle looks up (and to the side into directories called master) to find the nearest settings.gradle if none is specified. Then it evaluates the settings.gradle and checks whether the project in which your working directory is, is part of the multi-project build defined in that settings.gradle file. If so, it is executed in the context of the multi-project build, if not, it is executed as standalone build.

This means, if you call Gradle from inside ProjectA, you have a completely different build that probably als is configured differently, than if you call Gradle from inside ProjectB.

If you want to compose multiple multi-project builds into one build, you should instead use GradleBuild tasks or composite builds. In both cases the sub-build is completely independent and can itself be a multi-project build. Which one to use depends on the exact use-case.

Vampire
  • 35,631
  • 4
  • 76
  • 102
0

With gradle you should be using only a single settings.gradle file. See Multiple settings gradle files for multiple projects building

Also just follow gradle multiproject documentation.

tkruse
  • 10,222
  • 7
  • 53
  • 80