Skip to content

Instantly share code, notes, and snippets.

@CaiJingLong
Created April 12, 2020 05:42
Show Gist options
  • Save CaiJingLong/4ff22e8bfc41b5c0e1c14499c86f8057 to your computer and use it in GitHub Desktop.
Save CaiJingLong/4ff22e8bfc41b5c0e1c14499c86f8057 to your computer and use it in GitHub Desktop.
Depending on whether the IP is China, decide whether to use aliyun maven.
import groovy.json.JsonSlurper
buildscript {
ext.kotlin_version = '1.3.61'
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' }
} else {
google()
jcenter()
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.2'
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' }
} else {
google()
jcenter()
}
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
subprojects {
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.android.support'
&& details.requested.name.contains('appcompat-v7')) {
details.useVersion '27.1.1' //change version to your version
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment