2

While shifting my project from Ubuntu to Mac, I copied the Java dependencies and jars from the ~/.gradle/cacheon Ubuntu to ~/.gradle/caches/artifacts on Mac to avoid having gradle download the dependencies all over again. To my surprise, running gradle idea (we are using Intellij Idea) emptied the ~/.gradle/caches/artifacts folder and started downloading the dependencies again, nevertheless

I saw numerous resources and questions on SOF talk about forcing gradle to redownload the dependencies (using the --refresh-dependencies flag, for example), but none so far on how to prevent gradle from doing that and instead look into its local cache.

Is there a flag or switch which can help achieve this task?

I am using gradle 1.0-milestone-3, and unfortunately, don't have the privilege to upgrade it anytime soon.

satvik.t
  • 423
  • 4
  • 19

2 Answers2

1

There's --offline flag which forces Gradle not to access network resources. As a consequence it will use Gradle dependency cache and not try to refresh the dependencies from the remote server. See How to configure gradle to work "offline" (using cached dependencies).

Of course, as lance-java mentioned in his answer relocatable dependency cache is a v6.1+ feature (see Make dependency caches relocateable#1338) and therefore won't work for caches generated with earlier Gradle versions.

jannis
  • 4,843
  • 1
  • 23
  • 53
0

This was not supported before Gradle 6.1, are you using Gradle 6.1.1 or later?

Earlier versions of Gradle included the absolute file path in each item's cache key which made it difficult to copy a build cache from one machine and use it on another.

See the Gradle 6.1.1 Release Notes regarding the relocatable build cache

lance-java
  • 25,497
  • 4
  • 59
  • 101
  • I am using gradle 1.0-milestone-3; updated question with the same – satvik.t Apr 08 '20 at 14:25
  • As I said, prior to 6.1 the cache keys included the absolute file paths. So you'll only be able to copy a cache from one machine and use it on another if the files are in the exact same absolute file locations. There are possibly other issues which will prevent this working too – lance-java Apr 08 '20 at 14:57