Last active
July 5, 2020 07:00
-
-
Save CaiJingLong/8e5860755e4053397e7e8f45000d8dff to your computer and use it in GitHub Desktop.
中国的gradle配置
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import groovy.json.JsonSlurper | |
buildscript { | |
ext.kotlin_version = '1.3.72' | |
def isChina = false | |
try { | |
def connection = new URL('https://api.ip.sb/geoip').openConnection() | |
connection.setRequestMethod('GET') | |
def reader = new BufferedReader(new InputStreamReader(connection.inputStream)) | |
def text = reader.readLine() | |
def slurper = new JsonSlurper() | |
def states = slurper.parseText(text) | |
def country = states['country'] | |
isChina = country == 'China' | |
} catch (e) { | |
println(e) | |
} | |
ext.isChina = isChina | |
repositories { | |
if (isChina) { | |
maven { url 'https://maven.aliyun.com/repository/google' } | |
maven { url 'https://maven.aliyun.com/repository/jcenter' } | |
maven { | |
url 'https://storage.flutter-io.cn/download.flutter.io' | |
} | |
} else { | |
google() | |
jcenter() | |
} | |
} | |
dependencies { | |
classpath 'com.android.tools.build:gradle:3.6.3' | |
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" | |
} | |
} | |
allprojects { | |
repositories { | |
if (isChina) { | |
maven { url 'https://maven.aliyun.com/repository/google' } | |
maven { url 'https://maven.aliyun.com/repository/jcenter' } | |
maven { | |
url 'https://storage.flutter-io.cn/download.flutter.io' | |
} | |
} else { | |
google() | |
jcenter() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment