赞
踩
以前总是手动设置,今天在看gradle设置init脚本的时候,看到一个讲可以设置一个gradle启动初试执行脚本,于是想到是否可以在gradle每次初始化时,自动去替换工程中的maven仓库位置,指向阿里云。不然每次run都要开代理。
https://www.cnblogs.com/langtianya/p/5220212.html
这样我在.gradle下面建一个init.d的文件夹,然后放个build.gradle文件。
- allprojects {
- repositories {
- maven {
- url 'https://maven.aliyun.com/repository/public/'
- }
- maven {
- url 'https://maven.aliyun.com/repository/google/'
- }
- }
-
- buildscript {
- repositories {
- maven{ url 'https://maven.aliyun.com/repository/public/'}
- maven{ url 'https://maven.aliyun.com/repository/google/'}
- }
- }
-
- }
执行了一下,可以。
于是网上搜了一下,发现也有其他人想到这一点。好像比我多做了一步,把工程中的相应的依赖替换掉。
来自https://www.cnblogs.com/flying_bat/p/11653373.html
- allprojects {
- repositories {
- maven {
- url 'https://maven.aliyun.com/repository/public/'
- }
- maven {
- url 'https://maven.aliyun.com/repository/google/'
- }
-
- all { ArtifactRepository repo ->
- if (repo instanceof MavenArtifactRepository) {
- def url = repo.url.toString()
-
- if (url.startsWith('https://repo.maven.apache.org/maven2/') || url.startsWith('https://repo.maven.org/maven2')
- || url.startsWith('https://repo1.maven.org/maven2') || url.startsWith('https://jcenter.bintray.com/')
- || url.startsWith('https://maven.google.com/') || url.startsWith('https://dl.google.com/dl/android/maven2/')) {
- //project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL."
- remove repo
- }
- }
- }
- }
-
- buildscript {
- repositories {
- maven{ url 'https://maven.aliyun.com/repository/public/'}
- maven{ url 'https://maven.aliyun.com/repository/google/'}
-
- 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/')
- || url.startsWith('https://dl.google.com/dl/android/maven2/')) {
- //project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL."
- remove repo
- }
- }
- }
- }
- }
-
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。