0

I have a gradle project with a lot of dependencies, and running a simple task (that simply prints out the classpath) takes about 12 seconds, even though all the dependencies have been downloaded and are available in cache.

If I turn my network interface off, and run the same task, it completes in about a second.

So, the question is why is gradle talking to internet every time? Is there some flag I can set to make it use the cache more aggressively? I tried googling it, and there is a lot of discussion about how to force gradle NOT use the cache, but I could not find anything about the opposite.

In response to the question in comments, my repositories config looks like this:

repositories {
  maven { url "${artifactoryUrl}/jcenter" }
  maven { url "${artifactoryUrl}/libs-release-local" }
  maven { url "${artifactoryUrl}/libs-snapshot-local" }
  mavenCentral()
  maven { url "http://maven.twttr.com" }
}

($artifactoryUrl points to an instace of artifactory we are running internally).

Dima
  • 39,570
  • 6
  • 44
  • 70

1 Answers1

4

I know that if you have a dependency where you say that you always want the latest version, gradle will have to check all the repositories until it finds one.

If you don't want gradle to check remote repositories and just use its cache, you can use the --offline flag (see here).

Vivin Paliath
  • 94,126
  • 40
  • 223
  • 295
  • Yeah, I found the `--offline` flag, but the problem with it is that I keep forgetting to use it when typing the command :) How do you "say that you always want the latest version"? I did not even know it was possible. Maybe, I am doing to by accident, and that's what my problem is? – Dima Mar 02 '16 at 18:55
  • 1
    To get the latest version you just have to use a `+` in the version number ([see here](http://stackoverflow.com/a/10373813/263004)). Unfortunately, as far as I know, there is no way to tell gradle to use its cache without using the `--offline` flag. – Vivin Paliath Mar 02 '16 at 18:57
  • Hmm, I definitely don't have any pluses in the version numbers ... :-/ – Dima Mar 02 '16 at 19:03
  • 1
    By default gradle verifies that the dependency you have in your gradle cache is the same as the one available in the remote repository. It does this by checking the SHA checksum, and to do this it contacts the remote repo. As the answer says, adding `--offline` tells gradle not to check remote repos. – RaGe Mar 02 '16 at 19:43