title: Load property from external file into build.gradle
body: <p>I have this:</p>
  
  <pre><code>def loadProperties(String sourceFileName) {
      def config = new Properties()
      def propFile = new File(sourceFileName)
      if (propFile.canRead()) {
          config.load(new FileInputStream(propFile))
          for (Map.Entry property in config) {
              ext[property.key] = property.value;
          }
      }
  }
  
  loadProperties 'gradle.properties'
  </code></pre>
  
  <p>How do I reference the property (ndk.dir) in build.gradle?</p>
  
  <pre><code>def ndkBuild = new File("$ndk.dir", 'ndk-build')
  </code></pre>
  
  <p>And is there a better way of reading ndk.dir from file gradle.properties?
  And how do I use it in?</p>
  
  <pre><code>def ndkBuild = new File("$ndk.dir", 'ndk-build')
  </code></pre>
  
  <p>Full code:</p>
  
  <pre><code>task buildNative(type: Exec) {
      loadProperties 'gradle.properties'
      if (System.getenv('NDK_HOME') != null || "$ndk.dir" != null) {
          if ("$ndk.dir" != null) {
              def ndkBuild = new File("$ndk.dir", 'ndk-build')
          } else {
              def ndkBuild = new File(System.getenv('NDK_HOME'), 'ndk-build')
          }
          workingDir "jni"
          executable ndkBuild
      } else {
          throw new GradleException('Reason: NDK_HOME not set or ndk.dir is missing in gradle.properties...')
      }
  }
  
  def loadProperties(String sourceFileName) {
      def config = new Properties()
      def propFile = new File(sourceFileName)
      if (propFile.canRead()) {
          config.load(new FileInputStream(propFile))
          for (Map.Entry property in config) {
              ext[property.key] = property.value;
          }
      }
  }
  </code></pre>