Reputation: 75
I'm trying to set up a composite build. The current structure is
projectA
-build.gradle
-settings.gradle
-app
-build.gradle
projectB
-buid.gradle
-settings.gradle
-sdk
-build.gradle
I need to use projectB as a dependency in projectA, however, projectB still needs to function as a standalone project.
Here's what I have currently
ProjectA settings.gradle contains
includeBuild('../projectB')
ProjectA build.gradle contains
group "com.example"
projectA:App build.gradle contains
dependencies {
implementation 'com.example:projectB'
}
projectB build.gradle contains
group "com.example"
However, when I try to build projectA, I get the error:
Could not resolve com.example:projectB.
Required by:
project :app
What am I doing wrong here? I feel like it has something to do with the 'com.example', but I can't figure out what the correct way to reference the included project as a dependency is.
Upvotes: 6
Views: 2286
Reputation: 359
You are not substituting the dependency in project A. You can refer to example 6 in this section: https://docs.gradle.org/current/userguide/composite_builds.html#included_build_declaring_substitutions
In your case, you want to modify the settings.gradle file of project A to look something like:
includeBuild('../projectB') {
dependencySubstitution {
substitute module("com.example:projectB") using project(':projectB')
}
}
This will tell gradle that during the configuration phase, it should replace any dependency on com.example:projectB with project :projectB found in ../projectB.
Having said the above, it looks like you are actually interested in including the sdk module defined in projectB. If this is the case, you can replace using project(':projectB')
with using project(':sdk')
Upvotes: 7