title: How to let subprojects choose their own repository configurations in a multi-project build?
body: <p>I'm new to using build tools and working on multi-project environments in general but I'll try explain the best I can.</p>
  
  <h3>Structure</h3>
  
  <p>This is the directory structure. (there's more modules actually but I tried to keep it simple for the purpose of this question)</p>
  
  <pre><code>Project vcs repo root
  +---Project A/
  |       build.gradle
  |       settings.gradle
  |
  +---Project B/
  |       build.gradle
  |
  +---Project C/
  |   |   build.gradle
  |   \---libs/
  |   
  +---Project D/
  |       build.gradle
  |       settings.gradle
  |
  +---Shared libs/
  |
  \---build.gradle
  </code></pre>
  
  <p>Project depedencies:</p>
  
  <ul>
  <li><code>A</code> depends on <code>B</code> and <code>C</code>.</li>
  <li><code>D</code> depends on <code>B</code> and <code>A</code>.</li>
  </ul>
  
  <p>Each project can get its dependency from one of three places:</p>
  
  <ol>
  <li>mavenCentral</li>
  <li>a <code>libs</code> directory from its own root directory. (the <code>libs</code> dir under <code>Project C</code> is only for <code>Project C</code> to use)</li>
  <li><code>Shared libs</code> directory in the project's parent directory.</li>
  </ol>
  
  <p>however the libs folders contents are not guaranteed to be in certain format, (it is not a dir with all jars, there might be sub dirs and such)</p>
  
  <h3>Goal</h3>
  
  <p>I want each project to be buildable from the project's root directory, and I do not want to keep a redundant copy of repositories/dependencies of a child project in a parent project build. I should only have to provide the locations and possibly version numbers of child projects in the parent's build file.</p>
  
  <h3>My Attempt</h3>
  
  <p>in <code>C/build.gradle</code>:</p>
  
  <pre><code>apply plugin: 'java'
  repositories {
      mavenCentral()
      def myLibsDir = 'libs'
      flatDir name: 'Foo', dirs: "$myLibsDir/foo/4.20"
      //and then do a similar thing for shared libs if needed.
  }
  
  dependencies {
      // atrifacts we can get from mavenCentral or 'C/libs/foo/4.20'
  }
  </code></pre>
  
  <p>This works just fine for <code>Project C</code>, All tasks work as expected.</p>
  
  <p>then when setting up <code>A</code>:
  settings.gradle:</p>
  
  <pre><code>includeFlat 'Project B', 'Project C'
  </code></pre>
  
  <p>build.gradle:</p>
  
  <pre><code>repositories {
      mavenCentral()
      def sharedLibsDir = '../Shared libs'
      flatDir name: 'Blazer', dirs: "$sharedLibsDir/blz/pls/13.37"
  }
  dependencies {
      //non-subproject dependencies
      compile project('Project B')
      compile project('Project C')
  }
  </code></pre>
  
  <p>this <em>almost</em> works. only problem is that, unlike dependencies, each sub project's <code>repositories {}</code> is ignored and the parent's is used instead. So if <code>C</code> depends on something in <code>C/libs</code> I'd have to include that in <code>A/build.gradle</code> 's <code>repositories{}</code></p>
  
  <p>my guess is I could also use something like <a href="https://docs.gradle.org/current/userguide/userguide_single.html#sec:external_build" rel="nofollow">this</a> and then depend on the subproject's artifact(s) directly. Idk why exactly but this method seems harder to maintain.</p>