How to make gradle work offline with few simple config steps

I have been using cordova 5 for my hybrid app development which internally uses gradle build process to build my android apps. I notice that gradle goes to network repository of dependencies every time I build to check for updates(probably).
One of our customers wants to strictly avoid gradle doing a nework call and instead wants us to make the build work offline.
So far I have tried multiple ways to make gradle work offline. two of the standard ways are as follows:

  1. gradle --offline switch. I used this switch in the gradlew.bat files CMD_LINE_ARGS env variables and also tried putting it in the gradle_home\bin\gradle.bat but no effect. gradle still goes online.
  2. Tried to set the dependency cache expiry timeout in the resolutionStrategy for both changing as well as dynamic dependency versions but this also does not make any difference.

I see that even though the jar file ( gradle-1.3.0.jar is available in the local maven repository, gradle says can not find it even if it is trying to search in the right location (.m2/repository/…). (please note that I changed the repository to mavenLocal after the initial dependency download from mavenCentral)
Also gradle docs say that it caches dependencies by default for 24 hours, but I do not see this happening.
Why does gradle not honour any of the configurations ?
Why can’t there be a simple way to tell gradle not to go online once a repository of dependencies has already been downloaded ?
Also when gradle maintains its own dependency cache, why does it search for them in maven repository location ?
Is there a standard way to tell gradle to look into the gradle cache instead of the maven repo ?
Also can I make the cache expiry timeout infinite and how and exactly where in the build script ?

Using --offline should result in the behavior you want. How are you executing this build? Are you using the Gradle wrapper?

Thanks for the response.

I do not directly use gradlew or gradle to build. I am not sure if you are aware of apache cordova android build process. it uses gradle scripts to build android apk. when a cordova project is created , it creates a build.gradle file which has a gradle wrapper task. this task first downloads the gradle wrapper and then downloads the gradle dependencies and puts them in gradle caches folder in user-home dir. Since I am not directly using gradle , I am not sure how where to put the --offline switch. I tried setting this switch in the GRADLE_OPTS env variable but that gives invalid option error.
There is a gradlew.bat file also in the project. Can I set it in that file somewhere ?
Pasting my build.gradle script’s top few lines for reference

apply plugin 'android’
buildscript {
repository {

dependencies {
classpath: “”
configuration.all {
resolutionStrategy.cacheChangingModulesFor 365, 'days’
resolutionStrategy.cacheDynamicVersionsFor 365, ‘days’


Also can the cache expiry timeout be made infinite ? I am currently finding that it works for maximum of 500 days (approx). what’s this magic number ?

So to make it simple , I have the following requirement.

Given that I am using gradle wrapper from inside a cordova build,

  1. Can I have some configuration by which the gradle dependency cache will NEVER expire ?
  2. How can I use the --offline switch in this scenario (Please refer to my earlier response explaining my cordova project structure)


I guess my question is, what is executing gradlew.bat? If you are running it manually via the command line you can just add --offline. If it’s another script which is kicking it off you’ll need to 1) modify that script or 2) modify gradlew.bat itself. You can add --offline to the line set CMD_LINE_ARGS= in gradlew.bat.

I tried putting the --offline in the gradlew bat file as you have suggested but it has no effect on the build moreover the gradlew bat file gets overwritten every time I run the build. I even tried putting the --offline flag in the gradle.bat file in the gradle 2.2.1/bin (which gets downloaded by the gradle wrapper) but no,luck.
I notice that when I add the cache expiry timeout as 0 seconds (no caching) , the --offline flag has no effect.This means even if I do not configure any cache timeout , gradle cache will anyway expire after the default 24 hours and then the build will fail even though I have the --offline flag set in the gradle or gradlew batch files.

So as a last resort I want to know how to copy the gradle cache to the local maven repo so that the mavenLocal reppository can be configured in build.gradle ?
I know I can probably copy the artifacts from the gradle cache manually into the maven repo in the maven supported folder structure but I was looking for some official way from gradle to achieve this.