title: Change dependency through a task in gradle
body: <p>I've build a lib, that in order to compile the application needs to set the specific flavor and release/debug type. 
  However I'm trying to do this using a systemProperty when assembling the gradle via command. </p>
  
  <p>To do that I'm doing something like this:</p>
  
  <pre><code>gradlew init assembleRelease -D P="flavor1"
  </code></pre>
  
  <p>On the build.gradle of the application I created a task to consume this "P" system property like:</p>
  
  <pre><code>task init(type: JavaExec){
          systemProperty "Production", System.getProperty("P")   //this variable comes from command variable
          rootProject.ext.set("Production", systemProperties["Production"]);
  }
  </code></pre>
  
  <p>Despite all this the following code runs always before the init task:</p>
  
  <pre><code>dependencies{
     if(rootProject.ext.Production == "flavor1"){
        releaseCompile "compile with flavor1"
     }else{
        releaseCompile "compile with flavor2"
     }
  }
  </code></pre>
  
  <p>Is there any way to change dependencies on the task init, in order to create an apk based on flavor set by a system property on a command line? </p>
  
  <p><strong>Note</strong>: I have an application, which add a dependency of a lib, which has many flavors, and what I want to change on the fly via the command line is the dependency to add on the application of this lib.</p>