title: Gradle Android dependency product flavors
body: <p>I'd like to know if there is a way for a root project to define/inject some properties in it's dependencies. More specifically, the problem I'm having is that a library project has to know whether to take "free" or "pro" java sources and other resources before assemble/compile task is run. Kind of like specifying product flavors for library projects (that are inherited from it's parent project), but that isn't supported by the Android plugin for Gradle. Changing the library project structure, i.e. creating "free" and "pro" libs is not an option.</p>
  
  <p><strong>Edit:</strong>
  The best I've managed to achieve so far is something like this:</p>
  
  <p><strong>root:</strong> build.gradle</p>
  
  <pre><code>android {
      ...
  
      productFlavors {
          free, pro
      }
  
      sourceSets {
          free {
              project(':..:lib') {
                  groupFreePro = 'free'
                  // java.srcDirs = ['src', 'free/src']
               }
          }
  
          pro {
              project(':..:lib') {
                  groupFreePro = 'pro'
                  // java.srcDirs = ['src', 'pro/src']
              }
          }
      ...
      }
  }
  </code></pre>
  
  <p><strong>library:</strong> gradle.build</p>
  
  <pre><code>android {
      ...
      sourceSets {
          main {
                    java.srcDirs = [groupFreePro + '/src']
                    res.srcDirs = [groupFreePro + '/res']
               }
          }
      ...
      }
  }
  </code></pre>
  
  <p>That way I inject the groupFreePro variable into the lib project. But there is a problem with this approach:</p>
  
  <p>By the time, when the lib project get's to it's android -> sourceSets task the groupFreePro is always set to "pro". I presume that's because all the sourceSets at the root project are read (and not just the one variant that I want to build with; "free" for example) and thus the last set/task always overrides any previously set values of groupFreePro.</p>
  
  <p>If I try to set the value of groupFreePro any other way it either gets overriden (like in the above case), or I don't know the appropriate task/time/place where I should call this variable injection stuff to set the variable to the desired value. Uncommenting <code>java.srcDirs</code> in root project doesn't help either.</p>
  
  <p>I tried solving these problems on my own, but I'm really new to Gradle and also lack of proper documentation (at least for the Android part) leaves me guessing what to do most of the time so I do a lot of trial and error (but now I'm kind of stuck).</p>