How to prevent Gradle from downloading snapshots?

In general, I like the fact that Gradle downloads new copies of snapshots. However, there are situations where that can be a little scary, like standing in front of 200 people giving a live demonstration of Gradle.

What are reasonable strategies for temporarily disabling this, not including disconnecting from the internet?

Offline mode:
https://gradle.org/docs/current/userguide/dependency_management.html#sec:cache_command_line_options

You could also set the cache time very high (you’d have to do this before you resolved the snapshots).

You could use something like the dependency lock plugin and enforce a particular version vs using snapshots.

I need something that I can set up without having to add anything extra to the command line or my build script. Is there something I can set in my “gradle.properties” file to make one of these things happen?

Put this in an init script.

allprojects {
    configurations.all {
        resolutionStrategy.cacheChangingModulesFor 2628000, 'seconds'
    }
}
1 Like

Nice. I never really noticed init scripts before. Good learning opportunity. :slight_smile:

If I’ve run one or more builds with this in place, what exactly should I expect to happen if I comment out those lines and run the build again? Will that build possibly attempt to download snapshots, or will even this information be cached for a period?

The default caching period is 24 hours. Assuming it has been more than 24 hours since the last time it checked for a new snapshot, it would go ahead and do so.