title: assembleRelease task dependency - Ask for keystore password
body: <p>To avoid writing the keystore password in plain text, I'm trying to add a dependency to the <em>assembleRelease</em> task created by the android Gradle plugin.</p>
  
  <p>I've checked the Gradle documentation <a href="http://www.gradle.org/docs/current/userguide/tutorial_using_tasks.html#N102B0" rel="noreferrer">Manipulating existing tasks</a> but I'm unable to place the dependency where it should</p>
  
  <p>This is my task, defined in <em>$root$/myApp/build.gradle</em> above the android plugin. </p>
  
  <pre><code>task readPasswordFromInput &lt;&lt; {
      def console = System.console()
  
      ext.keystorePassword = console.readLine('\n\n\n&gt; Enter keystore password: ')
  }
  
  apply plugin: 'android'
  </code></pre>
  
  <p>Then, I've tried the two possibilities offered by Gradle: <em>task.dependsOn</em> and <em>task.doFirst</em>, but none works. The latter appears to be ignored, while <em>dependsOn</em> does add the dependency, but too late in the dependency chain. Running <em>./gradlew tasks --all</em> prints this</p>
  
  <pre><code>:assembleRelease - Assembles all Release builds [libs:ActionBarSherlock:bundleRelease, libs:DataDroid:bundleRelease, libs:SlidingMenu:bundleRelease]
      :compileRelease
      ...
      [SEVERAL TASKS]
      ...
      :packageRelease
      ...
      [SEVERAL TASKS]
      ...
      :readPasswordFromInput
  </code></pre>
  
  <p>The problem is, the keystore password is needed in the task <em>packageRelease</em></p>
  
  <p>Just as a side note, this works as I want</p>
  
  <pre><code>buildTypes {
          release {
              def console = System.console()
  
              ext.keystorePassword = console.readLine('\n\n\n&gt; IF building release apk, enter keystore password: ')
  
              debuggable false
  
              signingConfigs.release.storePassword = ext.keystorePassword
              signingConfigs.release.keyPassword = ext.keystorePassword
  
              signingConfig signingConfigs.release
          }
      }
  </code></pre>
  
  <p>but it asks for the password every single time you use <em>gradlew</em>, no matter if it's a <em>clean</em> or an <em>assemble</em></p>
  
  <p>Thanks!</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Thanks to @Intae Kim, here's my build.gradle version 2.0</p>
  
  <pre><code>task readPasswordFromInput &lt;&lt; {
      def console = System.console()
  
      ext.keystorePassword = console.readLine('\n\n\n&gt; Enter keystore password: ')
  
      android.signingConfigs.release.storePassword = ext.keystorePassword
      android.signingConfigs.release.keyPassword = ext.keystorePassword
  }
  
  tasks.whenTaskAdded { task -&gt;
      if (task.name == 'validateReleaseSigning') {
          task.dependsOn readPasswordFromInput
      }
  }
  
  apply plugin: 'android'
  </code></pre>
  
  <p>Then, the buildTypes</p>
  
  <pre><code>release {
      debuggable false
  
      signingConfig signingConfigs.release
  
      runProguard true
      proguardFile 'my-file.txt'
  }
  </code></pre>
  
  <p>Gradle executes correctly, but it only generates a release-unsigned.apk</p>