-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle
More file actions
212 lines (193 loc) · 7.03 KB
/
build.gradle
File metadata and controls
212 lines (193 loc) · 7.03 KB
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
id 'maven-publish'
id 'org.ajoberstar.grgit'
}
def utilsGroupId = "ai.elimu"
def utilsArtifactId = "common-utils"
def utilsVersionCode = 1000014
def utilsVersionName = '1.0.14-SNAPSHOT'
android {
namespace 'ai.elimu.common.utils'
compileSdk 35
defaultConfig {
minSdk 26
versionCode utilsVersionCode
versionName utilsVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '17'
}
publishing {
singleVariant("release") {
withSourcesJar()
}
}
}
dependencies {
implementation libs.androidx.core.ktx
implementation libs.androidx.appcompat
implementation libs.material
implementation libs.androidx.lifecycle.viewmodel
implementation libs.androidx.lifecycle.runtime.ktx
implementation libs.hilt.android
kapt libs.hilt.compiler
testImplementation libs.junit
androidTestImplementation libs.androidx.junit
androidTestImplementation libs.androidx.espresso.core
}
publishing {
publications {
release(MavenPublication) {
groupId = utilsGroupId
artifactId = utilsArtifactId
version = utilsVersionName
afterEvaluate {
from(components["release"])
}
}
}
repositories {
maven {
name = "GithubPackages"
url = uri("https://maven.pkg.github.com/elimu-ai/common-utils")
credentials(PasswordCredentials)
}
}
}
tasks.register('ensureCleanRepo') {
doLast {
if (!grgit.repository.jgit.status().call().clean) {
throw new GradleException('Git status is not clean, please stash your changes!')
}
}
}
tasks.register('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.
tasks.register('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: ['utils/build.gradle'])
try {
grgit.commit(message: "[gradle-release-task] prepare release $applicationId-$versionName")
} catch (Exception e) {
throw new GradleException("Failed to commit, error:\n $e")
}
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: ['utils/build.gradle'])
grgit.commit(message: "[gradle-release-task] prepare for next development iteration")
println "Done!"
}
}
tasks.register('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!"
}
}