Skip to content

Instantly share code, notes, and snippets.

@CaiJingLong
Last active July 5, 2020 07:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CaiJingLong/8e5860755e4053397e7e8f45000d8dff to your computer and use it in GitHub Desktop.
Save CaiJingLong/8e5860755e4053397e7e8f45000d8dff to your computer and use it in GitHub Desktop.
中国的gradle配置
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