Skip to content

/flags/gradle/gradle-offline

gradle --offline: build with cached dependencies only

The commands on this page have not been executed by our verification runner yet.updated
tool
Gradle
command
gradle, ./gradlew
flag
--offline
default
off (Gradle contacts repositories when the cache needs it)

./gradlew build --offline makes Gradle resolve dependencies and plugins only from its local cache (~/.gradle/caches) and never contact a repository. Builds no longer wait for network checks of dynamic versions (1.+, latest.release) and changing modules (snapshots), and they work on a plane or behind a broken proxy. If something is not in the cache, the build fails with No cached version of ... available for offline mode.

Usage

bash
./gradlew build               # online once: fills ~/.gradle/caches
./gradlew build --offline     # later: cache only

The Gradle wrapper itself needs its distribution in ~/.gradle/wrapper/dists; a wrapper that has never downloaded its Gradle version cannot start offline, whatever flags you pass.

Offline, online and refresh

ModeRepositories contactedDynamic and changing versions
(default)When the cache entry expired (24 hours for dynamic versions)Re-checked after the timeout
--offlineNeverLast cached resolution is used
--refresh-dependenciesAlways, for every dependencyRe-checked now
cacheDynamicVersionsFor / cacheChangingModulesForPer resolution strategyCustom timeouts in the build script

--offline and --refresh-dependencies are opposites; see --refresh-dependencies for when to force a refresh instead.

Tuning instead of going offline

When the goal is fewer network checks rather than no network, shorten what Gradle re-checks:

kotlin
configurations.all {
    resolutionStrategy.cacheDynamicVersionsFor(10, "minutes")
    resolutionStrategy.cacheChangingModulesFor(0, "seconds")
}

Pinning exact versions (no + ranges) and using dependency locking removes most remote checks without the risk of a cache miss.

Pitfalls

  • Plugins resolved through the plugins {} block also come from the cache. A plugin that was never downloaded fails offline with the same message family, or as Plugin was not found in any of the following sources.
  • A new dependency added while offline fails; go online for one build.
  • Different JDKs or Gradle versions on the same machine share the dependency cache, but a fresh CI container has an empty one: use --offline only where the cache is restored.
  • Maven's equivalent is mvn -o.

FAQ

How do I prepare a Gradle project for an offline build?

Run the same tasks once while online (for example ./gradlew build). Gradle stores every resolved dependency and plugin in ~/.gradle/caches; afterwards --offline can use them. The wrapper's Gradle distribution must also already be downloaded.

What is the error when a dependency is missing in offline mode?

Gradle reports that no cached version is available for offline mode, naming the module, for example 'No cached version of com.google.guava:guava:33.0.0-jre available for offline mode.' Go online once to download it.

Can I make Gradle offline by default?

There is no gradle.properties switch documented for it; pass --offline on the command line or toggle offline mode in the IDE (IntelliJ IDEA has a button in the Gradle tool window).

Sources