title: gradle script function to detect offline
body: <p>I want to add some code to my settings.gradle file</p>
  
  <pre><code>  if (!hasInternetAccess()) {
      startParameter.offline=true
    }
  </code></pre>
  
  <p>to allow gradle-code compilation if my computer has no internetconnection.</p>
  
  <p>does anybody know how a gradle script can implement hasInternetAccess()<code></code>?</p>
  
  <p>Background: <a href="https://stackoverflow.com/search?q=gradle+offline">gradle or android studios compilation fails if the computer has no internet connection</a>
  because it could not look for updated dependencies.</p>
  
  <p>instead of manually invoking gradle with the "--offline" parameter</p>
  
  <p>or adding</p>
  
  <pre><code>    startParameter.offline=true
  </code></pre>
  
  <p>to the settings.gradle file
  i am looking for a way to automate the configuration</p>
  
  <p>[update]</p>
  
  <p>i followed @opal-s link and added these lines to my settings.gradle file:</p>
  
  <pre><code>boolean isReachable = java.net.InetAddress.getByName("www.google.com").isReachable(1500)
  print "has internet: " + isReachable
  </code></pre>
  
  <p>in the debug output i always get</p>
  
  <pre><code>has internet: false
  </code></pre>
  
  <p>although i can successfully <code>ping www.google.com</code> </p>