Skip to content

Instantly share code, notes, and snippets.

@eugeneek
Created May 30, 2018 09:00
Show Gist options
  • Save eugeneek/79da94c6abad522bb63f36032239fdb5 to your computer and use it in GitHub Desktop.
Save eugeneek/79da94c6abad522bb63f36032239fdb5 to your computer and use it in GitHub Desktop.
Gradle build config (git versioning and dependencies)
apply plugin: 'com.android.application'
apply from: "$project.rootDir/scripts/script-git-version.gradle"
apply from: "$project.rootDir/scripts/dependencies.gradle"
ext {
// Version names
appVersionCode = getVersionCode()
appVersionName = getVersionName()
}
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.eugeneek"
minSdkVersion 19
targetSdkVersion 27
versionCode appVersionCode
versionName appVersionName
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
}
}
dependencies {
configurations {
all*.exclude group: 'com.android.support', module: 'support-v13'
}
implementation support.appCompat
implementation support.constraint
implementation moxy.runtime
annotationProcessor moxy.compiler
implementation toothpick.runtime
annotationProcessor toothpick.compiler
implementation cicerone.runtime
}
ext {
supportLibVer = "27.1.1"
constraintVer = "1.0.2"
permissionDispatcherVer = "2.4.0"
preferenceFixVer = "27.0.2.0"
retrofitVer = "2.3.0"
okHttp3Ver = "3.6.0"
roomVer = "1.0.0"
ciceroneVer = "3.0.0"
moxyVer = "1.5.3"
lifecycleVer = "1.1.1"
toothpickVersion = "1.1.3"
support = [
appCompat : "com.android.support:design:${supportLibVer}",
constraint : "com.android.support.constraint:constraint-layout:${constraintVer}"
]
network = [
retrofit : "com.squareup.retrofit2:retrofit:${retrofitVer}",
converterGson : "com.squareup.retrofit2:converter-gson:${retrofitVer}",
logging : "com.squareup.okhttp3:logging-interceptor:${okHttp3Ver}"
]
room = [
runtime : "android.arch.persistence.room:runtime:${roomVer}",
compiler : "android.arch.persistence.room:compiler:${roomVer}"
]
cicerone = [
runtime : "ru.terrakok.cicerone:cicerone:${ciceroneVer}"
}
moxy = [
runtime : "com.arello-mobile:moxy-app-compat:${moxyVer}",
compiler : "com.arello-mobile:moxy-compiler:${moxyVer}"
]
lifecycle = [
extention : "android.arch.lifecycle:extensions:${lifecycleVer}",
compiler : "android.arch.lifecycle:compiler:${lifecycleVer}"
]
toothpick = [
runtime : "com.github.stephanenicolas.toothpick:toothpick-runtime:${toothpickVersion}",
compiler : "com.github.stephanenicolas.toothpick:toothpick-compiler:${toothpickVersion}"
]
}
ext {
getVersionName = { ->
try {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'describe', '--tags', '--dirty'
standardOutput = stdout
}
return stdout.toString().trim() + "-b" + (System.getenv("BUILD_NUMBER") ?: "_local")
}
catch (ex) {
ex.printStackTrace()
return "v0.1-untagged" + "-b" + (System.getenv("BUILD_NUMBER") ?: "_local")
}
}
getVersionCode = { ->
try {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-list', '--all', '--count'
standardOutput = stdout
}
return Integer.parseInt(stdout.toString().trim())
}
catch (ex) {
ex.printStackTrace()
return -1
}
}
}
task printVersion() {
println("Version Name: $getVersionName")
println("Version Code: $getVersionCode")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment