-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.gradle
187 lines (168 loc) · 7.43 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
apply plugin: 'com.android.application'
apply plugin: 'org.ajoberstar.grgit'
android {
compileSdkVersion 32
defaultConfig {
applicationId "ai.elimu.vitabu"
minSdkVersion 24
targetSdkVersion 32
versionCode 1001006
versionName '1.1.6-SNAPSHOT'
setProperty("archivesBaseName", "${applicationId}-${versionCode}")
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
debug {
applicationIdSuffix ".debug"
versionNameSuffix "-debug"
manifestPlaceholders = [contentProviderApplicationId: "ai.elimu.content_provider.debug"]
buildConfigField("String", "CONTENT_PROVIDER_APPLICATION_ID", '"ai.elimu.content_provider.debug"')
buildConfigField("String", "ANALYTICS_APPLICATION_ID", '"ai.elimu.analytics.debug"')
}
qa_test {
initWith debug
applicationIdSuffix ".test"
versionNameSuffix "-test"
manifestPlaceholders = [contentProviderApplicationId: "ai.elimu.content_provider.test"]
buildConfigField("String", "CONTENT_PROVIDER_APPLICATION_ID", '"ai.elimu.content_provider.test"')
buildConfigField("String", "ANALYTICS_APPLICATION_ID", '"ai.elimu.analytics.test"')
}
release {
minifyEnabled false
manifestPlaceholders = [contentProviderApplicationId: "ai.elimu.content_provider"]
buildConfigField("String", "CONTENT_PROVIDER_APPLICATION_ID", '"ai.elimu.content_provider"')
buildConfigField("String", "ANALYTICS_APPLICATION_ID", '"ai.elimu.analytics"')
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.github.elimu-ai:model:model-2.0.66' // See https://jitpack.io/#elimu-ai/model
implementation 'com.github.elimu-ai:content-provider:1.2.26@aar' // See https://jitpack.io/#elimu-ai/content-provider
implementation 'com.github.elimu-ai:analytics:3.1.11@aar' // See https://jitpack.io/#elimu-ai/analytics
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'com.google.android.flexbox:flexbox:3.0.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
task ensureCleanRepo {
doLast {
if (!grgit.repository.jgit.status().call().clean) {
throw new GradleException('Git status is not clean, please stash your changes!')
}
}
}
task releaseClean(dependsOn: ensureCleanRepo) {
doLast {
def clean = true
def applicationId = android.defaultConfig.applicationId
String headCommitMessage = grgit.head().shortMessage
while (headCommitMessage.contains("[gradle-release-task]")) {
clean = false
println "Found git commit: $headCommitMessage"
if (headCommitMessage.indexOf("$applicationId-") > -1) {
def tagName = headCommitMessage.split("$applicationId-")[1]
println "Removing the git tag: $tagName"
try {
grgit.tag.remove {
names = [tagName]
}
} catch (Exception e) {
println "Error while removing git tag:\n $e"
}
}
println "Resetting the git commit permanently!"
grgit.reset(commit: "HEAD~1", mode: "hard")
headCommitMessage = grgit.head().shortMessage
}
if (clean){
println "Repository is already clean"
}
println "Done!"
}
}
// Task parameters:
// bumpVersion -> if available will specify new versionName directly and ignores the `bumpType` parameter.
// bumpType[major|minor|patch] -> will specify how the version bumping occurs.
task releasePrepare(dependsOn: ensureCleanRepo) {
doLast {
def applicationId = android.defaultConfig.applicationId
def versionName = android.defaultConfig.versionName
if (versionName.indexOf("-") > -1) {
versionName = versionName.split("-")[0]
}
// Prepare the release commit with the specific tag.
String buildText = buildFile.getText()
buildText = buildText.replaceFirst(/versionName(\s+.*)/, "versionName '$versionName'")
buildFile.setText(buildText) //replace the build file's text
grgit.add(patterns: ['app/build.gradle'])
grgit.commit(message: "[gradle-release-task] prepare release $applicationId-$versionName")
try {
grgit.tag.add {
name = versionName
message = "Release of $versionName"
}
} catch (Exception e) {
throw new GradleException("Failed to tag the repo, error:\n $e")
}
// Set new version name from input parameters.
def newVersionName
if (project.properties.containsKey("bumpVersion")) {
newVersionName = project.properties["bumpVersion"]
println "Bumping the version directly (bumpVersion=$newVersionName)"
} else if (project.properties.containsKey("bumpType")) {
def (major, minor, patch) = versionName.tokenize('.')
switch (bumpType) {
case "major":
major = major.toInteger() + 1
minor = 0
patch = 0
break
case "minor":
minor = minor.toInteger() + 1
break
case "patch":
patch = patch.toInteger() + 1
break
}
newVersionName = "$major.$minor.$patch"
} else {
throw new GradleException('Either bumpType or bumpVersion parameters should be provided')
}
// Prepare for next development iteration.
def versionCode = android.defaultConfig.versionCode
def newVersionCode = versionCode + 1
println "Bumping versionName from $versionName to $newVersionName"
println "Bumping versionCode from $versionCode to $newVersionCode"
buildText = buildFile.getText()
buildText = buildText.replaceFirst(/versionName(\s+.*)/, "versionName '$newVersionName-SNAPSHOT'")
buildText = buildText.replaceFirst(/versionCode(\s+.*)/, "versionCode $newVersionCode")
buildFile.setText(buildText) //replace the build file's text
grgit.add(patterns: ['app/build.gradle'])
grgit.commit(message: "[gradle-release-task] prepare for next development iteration")
println "Done!"
}
}
task releasePerform(dependsOn: ensureCleanRepo) {
doLast {
boolean force = false
if (project.properties.containsKey("force")) {
force = project.properties["force"]
}
println "Pushing the newest commits to the remote repository (force: $force)"
try {
grgit.push(force: force, tags: true)
} catch (Exception e) {
throw new GradleException("Failed to push to the repo,\n" +
" you can try using -Pforce=true parameter to force the push, error: \n$e")
}
println "Done!"
}
}