HotIceCream
HotIceCream

Reputation: 2309

Local gradle repository mirror

I need build android application on pc without network connection (or only with local network without external access).

How to create local repository mirror for gradle's binaries and application dependencies? Rather use local directory, but if it is impossible then may be I can use some artifactory service running on local machine?

Upvotes: 3

Views: 2663

Answers (2)

HotIceCream
HotIceCream

Reputation: 2309

Necessary to solve two problems:

  1. Downloading binary of gradle

  2. Downloading artifacts from remote repositories.

First problem solved with changing gradle/wrapper/gradle-wrapper.properties file:

distributionUrl=../../cache/gradle-2.2.1-all.zip

where value is path to local copy of gradle binary.

Second problem solved with Sonatype Nexus server. Start it and login with default account: admin/admin123

In settings of maven central repository proxy change parameter Override Local Storage Location on path to you cache folder.

In project replace mavenCentral() on next:

repositories {
    maven { url "http://localhost:8081/nexus/content/repositories/central/" }
}

Build you project. Now all deps of project located in you cache folder.

Then you can replace maven url on path to you cache folder:

repositories {
    maven { url "file://" + project.getRootDir().absolutePath + "/cache" }
}

Now you can copy cache folder to pc without network connection and build project absolutly offline

Upvotes: 4

Radim
Radim

Reputation: 4808

If you can build it once with connection Gradle will download the dependencies into its own cache (under Gradle user home directory). Then run it as ./gradlew --offline and it will not access the network.

Running local installation of Nexus or Artifcatory repository is another option. You can configure a proxy repository there that will again serve you cached artifacts even if you are without network connection.

Upvotes: 4

Related Questions