如何强制Gradle不下载依赖项(而是从其缓存中加载它们)?

huangapple go评论94阅读模式
英文:

How to force gradle to NOT to download dependencies (and load them from it's cache instead)?

问题

在将我的项目从Ubuntu迁移到Mac时,我将Java依赖项和jar从Ubuntu的~/.gradle/cache复制到Mac的~/.gradle/caches/artifacts,以避免让gradle再次下载依赖项。令我惊讶的是,运行gradle idea(我们使用Intellij Idea)会清空~/.gradle/caches/artifacts文件夹,并开始重新下载依赖项,尽管如此。

我看到许多关于如何强制gradle重新下载依赖项(例如使用--refresh-dependencies标志)的资源和stackoverflow上的问题,但迄今为止还没有关于如何阻止gradle这样做,而是查找其本地缓存的解决方法。

是否有一个标志或开关可以帮助实现这个任务?

我正在使用gradle 1.0-milestone-3,不幸的是,暂时没有升级的特权。

英文:

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.

答案1

得分: 1

有一个--offline标志,强制Gradle不访问网络资源。因此,它将使用Gradle依赖项缓存,而不会尝试从远程服务器刷新依赖项。参见 https://stackoverflow.com/q/32171524/4494577

当然,正如lance-java他的答案中提到的,可重定位的依赖项缓存是v6.1+的功能(参见使依赖项缓存可重定位#1338),因此不适用于使用早期Gradle版本生成的缓存。

英文:

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 https://stackoverflow.com/q/32171524/4494577.

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.

答案2

得分: 0

这在 Gradle 6.1 之前是不受支持的,您是否在使用 Gradle 6.1.1 或更高版本?

早期的 Gradle 版本在每个项目的缓存键中包含绝对文件路径,这使得从一台机器复制构建缓存并在另一台机器上使用变得困难。

请参阅Gradle 6.1.1 发布说明以了解可移植构建缓存的相关信息。

英文:

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

huangapple
  • 本文由 发表于 2020年4月8日 14:35:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/61094638.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定