-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
85 lines (69 loc) · 2.04 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import java.text.SimpleDateFormat
apply from: 'buildsystem/dependencies.gradle'
apply from: 'buildsystem/moduleAutoConfiguration.gradle'
buildscript {
ext {
versions = [
// Main
kotlin : '1.2.71',
gradleTools: '3.2.0',
buildTools : '28.0.2']
sdk = [
// App sdk version definitions
min : 21,
target : 28,
compile: 28]
applicationId = 'com.socros.android.app.gitez'
testRunner = 'android.support.test.runner.AndroidJUnitRunner'
}
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:${versions.gradleTools}"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}"
classpath "org.jetbrains.kotlin:kotlin-android-extensions:${versions.kotlin}"
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
static def generateVersionName() {
if (getCurrentBranch() == "master") {
return "${getLastMasterGitTagVersion()}"
} else {
return "${getBuildDate()} #${getGitCommitsCount()}.${getGitSha()}.${getCurrentBranch()}"
}
}
static def generateVersionCode() {
return getGitCommitsCount().toInteger()
}
static def getBuildDate() {
def df = new SimpleDateFormat("dd.MM.''yy")
df.setTimeZone(TimeZone.getTimeZone("UTC"))
return df.format(new Date())
}
static def getGitCommitsCount() {
return ("git rev-list ${getCurrentBranch()} --count").execute().text.trim()
}
static def getGitSha() {
return "git rev-parse --verify --short HEAD".execute().text.trim()
}
static def getCurrentBranch() {
return "git rev-parse --abbrev-ref HEAD".execute().text.trim()
}
static def getLastMasterGitTagVersion() {
def longVersionName = "git describe --tags master --long".execute().text.replace("v", "").trim()
def (fullVersionTag, versionBuild, gitSha) = longVersionName.tokenize('-')
// TODO simplify git tag version usage
// return fullVersionTag
def (versionMajor, versionMinor, versionPatch) = fullVersionTag.tokenize('.')
return sprintf("%s.%s.%s", [versionMajor, versionMinor, versionPatch])
}