Sometimes it’s necessary to run
gradle in offline mode. E.g. when having no internet connection or when you want to prevent
gradle to download files in case you have a limited download volume. This describes how to run gradle in offline mode.
In the end I describe two possible ways here. The first is the standard way you can find in the
gradle documentation. The second one a more improved one that imho is more convenient.
Using a parameter
The most easiest way is to simply add the parameter
--offline. This prevents that
gradle is using the network for any communication. The disadvantage of that solution is that you have to add that parameter to every command.
The following code snippet shows that you can do that by simply adding the parameter to the
# running the build task
gradle build --offline
A much more convenient way is to have an
init.gradle file that can be set globally for all
In that case simply add a file called
init.gradle in the folder
.gradle of the user home directory. That file will be executed for every
gradle build. This might look like the following:
// adding a hint so you remember when gradle is running in offline mode
println "gradle in offline mode"
Having the hint there prints you
gradle in offline mode before the build so you don’t forget the offline mode is active.
So you only have to set the boolean value to
false depending on whether you want to run offline or online.