无尽码路

清凉夏日,您升官了吗?
让Gradle飞起来
at 2023-06-14 16:40:40, by 鹏城奋青

gradle构建系统令人又爱又恨,我们必须解决两个问题才能爱。

1、Gradle本身一般有百十来M,下载过程那是相当漫长痛苦,在此我们要感谢腾讯云提供了镜像,请打开项目的gradle/wrapper/gradle-wrapper.properties,将distributionUrl的值换成如下形式,具体版本自个留意。

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://mirrors.cloud.tencent.com/gradle/gradle-7.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

2、Gradle依赖项的下载也是非常慢的,在此我们要感谢阿里云提供仓库镜像,在构建脚本中将仓库地址改一下,例如:

// 构建脚本为kotlin的写法
repositories {
    // 源: https://repo1.maven.org/maven2/
    maven("http://maven.aliyun.com/repository/central") {
        isAllowInsecureProtocol = true
    }
    // 源: https://maven.google.com/
    maven("http://maven.aliyun.com/repository/google") {
        isAllowInsecureProtocol = true
    }
    // 源: https://plugins.gradle.org/m2/
    maven("http://maven.aliyun.com/repository/gradle-plugin") {
        isAllowInsecureProtocol = true
    }
    // 源: http://jcenter.bintray.com/
    maven("http://maven.aliyun.com/repository/jcenter") {
        isAllowInsecureProtocol = true
    }
    // 源: central和jcenter的聚合
    maven("http://maven.aliyun.com/repository/public") {
        isAllowInsecureProtocol = true
    }
    // 源: github
    maven("http://maven.aliyun.com/nexus/content/repositories/releases") {
        isAllowInsecureProtocol = true
    }
    google()
    gradlePluginPortal()
    mavenCentral()
    maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
}
// 构建脚本为groovy的写法
repositories {
        // 源: https://repo1.maven.org/maven2/
        maven {
            url "http://maven.aliyun.com/repository/central"
            allowInsecureProtocol true
        }
        // 源: https://maven.google.com/
        maven {
            url "http://maven.aliyun.com/repository/google"
            allowInsecureProtocol true
        }
        // 源: https://plugins.gradle.org/m2/
        maven {
            url "http://maven.aliyun.com/repository/gradle-plugin"
            allowInsecureProtocol = true
        }
        // 源: http://jcenter.bintray.com/
        maven {
            url "http://maven.aliyun.com/repository/jcenter"
            allowInsecureProtocol true
        }
        // 源: central和jcenter的聚合
        maven {
            url "http://maven.aliyun.com/repository/public"
            allowInsecureProtocol true
        }
        // 源: github
        maven {
            url "http://maven.aliyun.com/nexus/content/repositories/releases"
            allowInsecureProtocol true
        }
        google()
        gradlePluginPortal()
        mavenCentral()
        maven {
            url "https://maven.pkg.jetbrains.space/public/p/compose/dev"
        }
}