gradle set up

C:\Users\Administrator.gradle\gradle.properties

config 复制代码
## For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
#
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx1024m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
#
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. For more details, visit
# https://developer.android.com/r/tools/gradle-multi-project-decoupled-projects
# org.gradle.parallel=true
#Fri Aug 01 12:16:42 CST 2025
systemProp.http.proxyHost=proxy.app
systemProp.http.proxyPort=8080
systemProp.https.proxyHost=proxy.app
systemProp.https.proxyPort=8080

C:\Users\Administrator.gradle\init.gradle.kts

config 复制代码
val CENTRAL_URL = "https://repo.maven.apache.org/maven2"
val JCENTER_URL = "https://jcenter.bintray.com"
val GOOGLE_URL = "https://dl.google.com/dl/android/maven2"
val GRADLE_PLUGIN_URL = "https://plugins.gradle.org/m2"

val MIRROR_CENTRAL_URL = "https://maven.aliyun.com/repository/central"
val MIRROR_JCENTER_URL = "https://maven.aliyun.com/repository/jcenter"
val MIRROR_GOOGLE_URL = "https://maven.aliyun.com/repository/google"
val MIRROR_GRADLE_PLUGIN_URL = "https://maven.aliyun.com/repository/gradle-plugin"

val mirrorMap = mapOf(
    CENTRAL_URL to MIRROR_CENTRAL_URL,
    JCENTER_URL to MIRROR_JCENTER_URL,
    GOOGLE_URL to MIRROR_GOOGLE_URL,
    GRADLE_PLUGIN_URL to MIRROR_GRADLE_PLUGIN_URL
)

fun String.normalizeUrl(): String = this.trimEnd('/')


fun RepositoryHandler.replaceWithMirrorRepos(logger: Logger) {
    val mavenRepos = this.toList()
        .filterIsInstance<MavenArtifactRepository>()
        .associateWith { it.url.toString().normalizeUrl() }
    
    val applyRepos = mavenRepos.filter { (_, url) -> 
        mirrorMap.containsKey(url) && !mavenRepos.containsValue(mirrorMap[url])
    }

    applyRepos.forEach { (repo, url) ->
        val mirrorUrl = mirrorMap[url]!!
        val nrp = maven { setUrl(mirrorUrl) }
        remove(nrp)
        val index = indexOf(repo)
        add(index, nrp)
        remove(repo)
        logger.lifecycle("添加镜像(${index}): $url -> $mirrorUrl")
    }
    applyRepos.keys.forEach { repo ->
        addLast(repo)
    }
}


gradle.settingsEvaluated {
    pluginManagement {
        repositories {
            replaceWithMirrorRepos(logger)
        }
    }
    dependencyResolutionManagement {
        repositories {
            replaceWithMirrorRepos(logger)
        }
    }
}

allprojects {
    buildscript {
        repositories {
            replaceWithMirrorRepos(logger)
        }
    }
    repositories {
        replaceWithMirrorRepos(logger)
    }
}
相关推荐
火柴就是我8 小时前
让我们实现一个更好看的内部阴影按钮
android·flutter
砖厂小工15 小时前
用 GLM + OpenClaw 打造你的 AI PR Review Agent — 让龙虾帮你审代码
android·github
张拭心15 小时前
春节后,有些公司明确要求 AI 经验了
android·前端·人工智能
张拭心15 小时前
Android 17 来了!新特性介绍与适配建议
android·前端
Kapaseker18 小时前
Compose 进阶—巧用 GraphicsLayer
android·kotlin
黄林晴18 小时前
Android17 为什么重写 MessageQueue
android
阿巴斯甜2 天前
Android 报错:Zip file '/Users/lyy/develop/repoAndroidLapp/l-app-android-ble/app/bu
android
Kapaseker2 天前
实战 Compose 中的 IntrinsicSize
android·kotlin
xq95272 天前
Andorid Google 登录接入文档
android
黄林晴2 天前
告别 Modifier 地狱,Compose 样式系统要变天了
android·android jetpack