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?
Dependency types To add a dependency to your project, specify a dependency configuration such as implementation in the dependencies block of your module's build.gradle file.
The subproject producer defines a task named buildInfo that generates a properties file containing build information e.g. the project version. You can then map the task provider to its output file and Gradle will automatically establish a task dependency.
Transitive dependencyA variant of a component can have dependencies on other modules to work properly, so-called transitive dependencies. Releases of a module hosted on a repository can provide metadata to declare those transitive dependencies. By default, Gradle resolves transitive dependencies automatically.
At runtime, Gradle will locate the declared dependencies if needed for operating a specific task. The dependencies might need to be downloaded from a remote repository, retrieved from a local directory or requires another project to be built in a multi-project setting. This process is called dependency resolution.
In my case the problem was that my subproject had settings.gradle
with
rootProject.name = 'MySubProject'
removing the file fixed it. (It seems you must not have the file at all, it is not enough to remove the property.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With