Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle offline how to cache the dependencies

I am doing nightly gradle builds on a server where I checkout the repositories from git and build them.However, there is a proxy where gradle cannot download any repository. I tried running gradlew offline mode then I get an error telling me that

"No cached version of" and then the name of the dependency.

This is obviously because I never downloaded the dependency, I was thinking of manually downloading the dependencies cache them and use that gradle cache on the server where builds can access it. My question is as follows :

  1. Is there any way I can download a .jar file or .pom file manually and then cache them ?_
  2. How would i cache a jar file in the $Home/.gradle/caches directory ? I tried just putting it there but it doesn't work .

any ideas?

like image 964
Ali Hamie Avatar asked Jun 09 '16 18:06

Ali Hamie


People also ask

How do I cache Gradle dependencies?

Generally, you can refresh dependencies in your cache with the command line option --refresh-dependencies. You can also delete the cached files under ~/. gradle/caches . With the next build Gradle would attempt to download them again.

How do I sync Gradle offline?

If we need to use the offline mode, just go to the Gradle window and click the Toggle Offline Mode button: After we click the button to enable offline mode, we can reload all dependencies and find that offline mode works.

Where Gradle dependencies are store in locally?

Gradle's local repository folder is: $USER_HOME/. gradle/caches/modules-2/files-2.1.


2 Answers

Usually Gradle retrieves dependencies on demand, only if and when they are need. To make Gradle download all dependencies beforehand (and thus populate the local cache), you can use a task like

task resolveAllDependencies {
    description "Resolves all transitive dependencies (e.g. to build offline later)."

    doLast {
        configurations.all {
            it.resolve()
        }
    }
}

After running this task, you should be able to successfully build with --offline.

like image 165
sschuberth Avatar answered Sep 24 '22 23:09

sschuberth


In Android Studio sync the dependencies once then go to

  • File > Settings > Build & Execution > Gradle > Enable Offline Mode > Ok!
like image 33
DarShan Avatar answered Sep 21 '22 23:09

DarShan