美文网首页
Gradle使用国内源(阿里云源)

Gradle使用国内源(阿里云源)

作者: 简单点的笨演员 | 来源:发表于2021-03-29 14:24 被阅读0次

    Gradle在国内经常抽风,一直使用梯子来使用倒是没有出现什么问题,今天梯子被墙了,Gradle就用不了。最近好像查的有点严,估计梯子一时好不了,试试换gradle国内源。没有想到换了国内源比用梯子更快,故特在此记录一下。

    关闭Gradle的代理(如果没有设置代理跳过这一步):

    打开文件C:\Users\Administrator.gradle\gradle.properties,注释设置代理的行。

    ## 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. More details, visit
    # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
    # org.gradle.parallel=true
    #Sat Jan 23 16:06:06 CST 2021
    
    #systemProp.http.proxyHost=127.0.0.1
    #systemProp.http.proxyPort=1081
    #systemProp.https.proxyHost=127.0.0.1
    #systemProp.https.proxyPort=1081
    

    更换Gradle国内源

    打开项目根目录的gradle.properties,注释所有google()和jcenter()的行,添加阿里云的源:

    // Top-level build file where you can add configuration options common to all sub-projects/modules.
    
    buildscript {
        
        repositories {
           // google()
           // jcenter()
            maven { url 'https://plugins.gradle.org/m2/' }
            maven { url 'https://maven.aliyun.com/nexus/content/repositories/google' }
            maven { url 'https://maven.aliyun.com/nexus/content/groups/public' }
            maven { url 'https://maven.aliyun.com/nexus/content/repositories/jcenter'}
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.2.0'
            
    
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }
    
    allprojects {
        repositories {
          //  google()
          //  jcenter()
            maven { url 'https://plugins.gradle.org/m2/' }
            maven { url 'https://maven.aliyun.com/nexus/content/repositories/google' }
            maven { url 'https://maven.aliyun.com/nexus/content/groups/public' }
            maven { url 'https://maven.aliyun.com/nexus/content/repositories/jcenter'}
        }
    }
    
    task clean(type: Delete) {
        delete rootProject.buildDir
    }
    

    参考:
    https://www.jianshu.com/p/319e7a8faa6a

    相关文章

      网友评论

          本文标题:Gradle使用国内源(阿里云源)

          本文链接:https://www.haomeiwen.com/subject/hwcbhltx.html