【springboot】菜鸟学习笔记20230606-gradle快速镜像配置

1、单项目镜像配置,build.gradle,建议直接跳过,使用2.一劳永逸

项目默认build.gradle配置:

repositories {
    mavenCentral()
}

使用阿里云gradle镜像,且注意gradle版本。

buildscript {
 repositories {
  maven { url 'https://maven.aliyun.com/repository/google/' }
  maven { url 'https://maven.aliyun.com/repository/jcenter/'}
 }
 dependencies {
  classpath 'com.android.tools.build:gradle:X.X.X'

  // NOTE: Do not place your application dependencies here; they belong
  // in the individual module build.gradle files
 }  
}

allprojects {
 repositories {
  maven { url 'https://maven.aliyun.com/repository/google/' }
  maven { url 'https://maven.aliyun.com/repository/jcenter/'}
 }
}

2、一劳永逸,全局配置,需要定位到系统用户下的.gradle文件夹,例如:windows系统默认为:C:\Users\Administrator\.gradle,在这个目录下新建init.gradle文件,使用如下阿里云镜像配置:

allprojects{
 repositories {
  def ALIYUN_REPOSITORY_URL = 'https://maven.aliyun.com/repository/public/'
  def ALIYUN_JCENTER_URL = 'https://maven.aliyun.com/repository/jcenter/'
  def ALIYUN_GOOGLE_URL = 'https://maven.aliyun.com/repository/google/'
  def ALIYUN_GRADLE_PLUGIN_URL = 'https://maven.aliyun.com/repository/gradle-plugin/'
  all { ArtifactRepository repo ->
   if(repo instanceof MavenArtifactRepository){
    def url = repo.url.toString()
    if (url.startsWith('https://repo1.maven.org/maven2/')) {
     project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_REPOSITORY_URL."
     remove repo
    }
    if (url.startsWith('https://jcenter.bintray.com/')) {
     project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_JCENTER_URL."
     remove repo
    }
    if (url.startsWith('https://dl.google.com/dl/android/maven2/')) {
     project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_GOOGLE_URL."
     remove repo
    }
    if (url.startsWith('https://plugins.gradle.org/m2/')) {
     project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_GRADLE_PLUGIN_URL."
     remove repo
    }
   }
  }
  maven { url ALIYUN_REPOSITORY_URL }
  maven { url ALIYUN_JCENTER_URL }
  maven { url ALIYUN_GOOGLE_URL }
  maven { url ALIYUN_GRADLE_PLUGIN_URL }
 }
}

完成配置后,再使用 ./gradlew build编译项目,下载依赖将超快。

你可能感兴趣的:(springboot,spring,boot,学习,笔记)