1. 程式人生 > >加速你的gradle構建,新增阿里雲映象

加速你的gradle構建,新增阿里雲映象

加速你的gradle構建

gradle的構建速度真是讓人抓狂,經常一構建都卡死,卡半天,最後優化了一下如下

1新建一個名為gradle.properties檔案放在.gradle目錄下

可以根據你的電腦配置jvmargs的大小

# IDE (e.g. Android Studio) users:
# Settings specified in this file will override any Gradle settings
# configured through the IDE.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html # The Gradle daemon aims to improve the startup and execution time of Gradle. # When set to true the Gradle daemon is to run the build. # TODO: disable daemon on CI, since builds should be clean and reliable on servers org.gradle.daemon=true
# Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. # Default value: -Xmx10248m -XX:MaxPermSize=256m org.gradle.jvmargs=-Xmx1048m -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 # Enables new incubating mode that makes Gradle selective when configuring projects. # Only relevant projects are configured which results in faster builds for large multi-projects. # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:configuration_on_demand org.gradle.configureondemand=true

這裡寫圖片描述
這裡寫圖片描述

2下載gradle-xxx-all.zip

下載對應的zip放入目錄下會自動解壓

這裡寫圖片描述

3在.gradle根目錄下新增一個名叫init.gradle的檔案新增阿里雲映象

  repositories {  

    def REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/groups/public/'  
      all { ArtifactRepository repo ->  
        if(repo instanceof MavenArtifactRepository){  
          def url = repo.url.toString()  
          if (url.startsWith('https://repo1.maven.org/maven2') || url.startsWith('https://jcenter.bintray.com/')) {  
            project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL."  
            remove repo  
          }  
       }  
    }  
    maven {  
      url REPOSITORY_URL  
    }  
  }  
}  

然後享受飛一般的構建速度吧biubiu。。。。