gradle项目 避免每次下载gradle文件/解决依赖下载慢的问题

 

参考:https://www.jb51.net/article/114276.htm

避免每次下载gradle文件

一、使用已存在的 gradle 版本

打开目录 ~/.gradle/wrapper/dists 查看当前已经下载了什么版本的 gradle

修改项目的 gradle/wrapper/gradle-wrapper.properties 文件

1

2

3

distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip

# 修改为当前已经存在的版本,假设当前已经存在的版本为2.14.1

distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip

重新打开 Android Studio 或者重新运行 assemble 即可。

二、手动下载 gradle

~/.gradle/wrapper/dists保存着下载好的gradle

 

下载完成后,将 zip 文件移至 gradle 指定版本目录下即可。

1

$ mv gradle-3.3-all.zip ~/.gradle/wrapper/dists/gradle-3.3-all/55gk2rcmfc6p2dg9u9ohc3hw9/gradle-3.3-all.zip

这里说明一下,以上只适用于 Linux 平台和 Mac 平台。    

Windows放哪?赶紧换系统吧(自行解决,Windows 也有类似的目录)。

再有一点,中间的55gk2rcmfc6p2dg9u9ohc3hw9每个人的都是不一样的,这是随机生成的。

接下来我们重新执行 assemble 命令,就会发现,直接跳过了原来的 Download 阶段,直接对我们刚才下载的 gradle-3-3.zip 文件进行了解压。

1

2

3

4

$ ./gradlew app:assemble        

Unzipping /Users/jeremyhe/.gradle/wrapper/dists/gradle-3.3-all/55gk2rcmfc6p2dg9u9ohc3hw9/gradle-3.3-all.zip to /Users/jeremyhe/.gradle/wrapper/dists/gradle-3.3-all/55gk2rcmfc6p2dg9u9ohc3hw9

Set executable permissions for: /Users/jeremyhe/.gradle/wrapper/dists/gradle-3.3-all/55gk2rcmfc6p2dg9u9ohc3hw9/gradle-3.3/bin/gradle

Starting a Gradle Daemon (subsequent builds will be faster)

解决依赖下载慢的问题

https://my.oschina.net/abcfy2/blog/783743

build.gradle中需要配置

buildscript {
    repositories {
        maven {
            url "https://maven.aliyun.com/nexus/content/groups/public"
        }
        maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
        maven { url 'https://maven.aliyun.com/repository/google' }
        maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
        maven { url 'https://maven.aliyun.com/repository/jcenter'}
    }
allprojects {
    repositories {
//        mavenCentral()
//        jcenter()
//        google()
        maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
        maven { url 'https://maven.aliyun.com/repository/google' }
        maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
        maven { url 'https://maven.aliyun.com/repository/jcenter'}

    }
}

 

 

官方文档中终于被我找到了:

plugin的DSL配置变成了plugins {}

如果使用了plugins {}这个闭包定义的插件依赖,就不再使用buildscript {}了,官方默认会从https://plugins.gradle.org/m2/这个仓库去查找插件以及依赖,如果要覆盖这个仓库,不在build.gradle中配置,而是在settings.gradle中,详见官方文档.

settings.gradle中配置

pluginManagement  {
    repositories {
maven {
    url 'https://maven.aliyun.com/repository/gradle-plugin'
}
        maven {
            url 'https://maven.aliyun.com/nexus/content/groups/public'
        }

    }

}

以上解决了settings.gradle的配置

又遇到了新问题:

原来是http不安全 需要用https ;

所有plugins{}的DSL 都需要用

pluginManagement  {
    repositories {
maven {
    url 'https://maven.aliyun.com/repository/gradle-plugin'
}
        maven {
            url 'https://maven.aliyun.com/nexus/content/groups/public'
        }

    }

}

终于成功的搭起groovy项目来了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值