I have a Multi project gradle project with the following structure.
Project A: The top level project that all sub projects reside in.
SubProject B:
SubProject C:
SubProject D:
SubProject E:
SubProject Shared: Every 'SubProject' has a dependency to this project "compile project(':Shared')"
Everything works correctly when running Gradle tasks from the top level 'Project A'
However, when I try to run an individual task on a subproject such as 'SubProject C' I get the following error.
FAILURE: Build failed with an exception
What went wrong:
A problem occurred evaluating root project 'SubProject C'.
Project with path ':Shared' could not be found in root project 'SubProject C'.
I think I see the problem here, Gradle thinks my sub project is a root project? However I do not know how to resolve this.
My top level settings.gradle file looks like this
rootProject.name = 'Project A'
include 'SubProject B'
include 'SubProject C'
include 'SubProject D'
include 'SubProject E'
include 'SubProject Shared'
This is my build.gradle file for 'SubProject C'
dependencies {
compile project(':Shared')
}
Bonus question... Do the sub projects need a settings.gradle file with the 'rootProject.name' set as the sub projects name?
I think the issue is with your settings.gradle file.
Replace the your settings.gradle file with below code.
rootProject.name = 'Project A'
include 'SubProject B',':SubProject C',':SubProject D',':SubProject E'
include ':SubProject Shared'
Try running the build script of 'SubProjectC'. Hope it will work.
And answer for your second question.
We don't need seperate settings.gradle for each subprojects.