In multi-project config, wrong repository is being used

I have 2 subprojects: ProjectA and ProjectB.

ProjectA uses ArtifactX from Repository1. ProjectB uses ArtifactY from Repository2. If I just set up the settings.gradle file and run build from the parent directory, all works well and both subprojects (A & B) build correctly.

If I add a compile project dependency on ProjectB into ProjectA’s build.gradle file, then Gradle fails while trying to build ProjectA complaining about not finding ArtifactY in Repository1 (it’s not there, but rather it is in Repository2).

I expected the project dependency to provide the JAR file from ProjectB to be added to the classpath of the ProjectA build. I also expect Project B to complete before ProjectA build starts. The repos for each subproject are specified explicitly named in the respective build,gradle file for the subprojects.

Each project will use only its configured repositories for dependency resolution. When I depend on another project I don’t get the jars as resolved by that project, because we have to do dependency resolution at the project level (if one of projectB’s dependencies conflicts with one from projectA). If a project dependency brings in a transitive dependency that isn’t located in any of the dependent project’s repositories, resolution will fail.

Think of it this way, if projectB was instead an external dependency (i.e. I was getting it from say, maven central) and it defined a dependency not found in any of my configured repos, the build would also fail. Your two options are either, put the required dependencies in Repository1, or add Repository2 to ProjectA.

Thanks, Mark.

I can’t deploy to repo1, so I added repo2 to projectA - success!

I also added both repos to the parent level build.gradle file and removed any repos from each of the project’s build.gradle…that worked as well.