#!/bin/bash
#替换gradle国内镜像源
sed -i 's|services.gradle.org/distributions|mirrors.cloud.tencent.com/gradle|g' gradle/wrapper/gradle-wrapper.properties
# 备份原始文件
cp settings.gradle settings.gradle.bak

# 清空并添加 pluginManagement.repositories 配置
sed -i '/pluginManagement {/,/}/ {
    /repositories {/,/}/ {
        /google()/d;
        /mavenCentral()/d;
        /gradlePluginPortal()/d;
    }
}' settings.gradle

sed -i '/pluginManagement {/,/}/ {
    /repositories {/a \
        maven{url=uri("https://maven.aliyun.com/repository/google")}\n\
        maven{url=uri("https://maven.aliyun.com/repository/central")}\n\
        maven{url=uri("https://maven.aliyun.com/repository/gradle-plugin")}\n\
        google()\n\
        mavenCentral()\n\
        gradlePluginPortal()
}' settings.gradle

# 清空并添加 dependencyResolutionManagement.repositories 配置
sed -i '/dependencyResolutionManagement {/,/}/ {
    /repositories {/,/}/ {
        /google()/d;
        /mavenCentral()/d;
    }
}' settings.gradle

sed -i '/dependencyResolutionManagement {/,/}/ {
    /repositories {/a \
        maven{url=uri("https://maven.aliyun.com/repository/google")}\n\
        maven{url=uri("https://maven.aliyun.com/repository/central")}\n\
        google()\n\
        mavenCentral()
}' settings.gradle
