I spent a lot of time to resolve my as I thought pretty usual project structure, but couldn't find any appropriate solution.
Project structure:
some_local_dir_with_git_repos
git_repo_of_project_A/
build.gradle
git_repo_of_project_B/
build.gradle
git_repo_of_project_Core/
Projects A and B should include Core sources.
"some_local_dir_with_git_repos" is not under Git, so I don't want to add any settings.gradle into it.
Is there a graceful solution?
ADDED:
Thanks to @peter-niederwieser and link he provided (with his answer in it - https://stackoverflow.com/a/20807550/1336772).
I made my settings.gradle of A and B projects looks like that:
include ':Core'
project(':Core').projectDir = new File('../git_repo_of_project_Core/')
And added these lines to build.gradle:
dependencies {
compile project(':Core')
}
After 'File -> Invalidate caches / Restart' (resolves 'cannot resolve symbol' issue in Android Studio) and 'Build -> Rebuild project' (resolves ClassNotFoundException issue) it works fine for me.
A good guideline is to build together what's versioned together. So if you have three Git repositories, you'd have three builds, and they would exchange artifacts via a binary repository (e.g. Artifactory or Nexus).
If you must have one build spanning multiple Git repositories, some options are to create an uber repository using Git submodules, to pass the location of
settings.gradle
via--settings-file
, or to run the build from the directory containingsettings.gradle
. Also, you may have to configure the locations of project directories as shown in defining subprojects in a deeply nested directory tree.