-
Notifications
You must be signed in to change notification settings - Fork 7
/
build.gradle
237 lines (203 loc) · 6.64 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
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
buildscript {
ext.isPreRelease = (project.hasProperty("preRelease") && project.property("preRelease").toBoolean() == true)
ext.getVersionName = {
return "${versionMajor}.${versionMinor}.${versionPatch}" + (isPreRelease ? "-SNAPSHOT" : '')
}
ext.getShortCommitSha = {
def gitSha = System.getenv("CIRCLE_SHA1")
if(gitSha != null) return gitSha.substring(0, 7) else return ""
}
ext["signing.keyId"] = System.getProperty('signing.keyId')
ext["signing.password"] = System.getProperty('signing.password')
ext["signing.secretKeyRingFile"] = System.getProperty('signing.secretKeyRingFile')
repositories {
google()
maven { url 'https://repo.gradle.org/gradle/libs-releases' }
}
}
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.9.0'
id 'java-gradle-plugin'
id 'maven-publish'
id "com.diffplug.spotless" version '6.19.0'
id "io.github.gradle-nexus.publish-plugin" version "1.0.0"
}
apply plugin: "com.diffplug.spotless"
spotless {
format 'misc', {
target '**/*.gradle', '**/*.md', '**/.gitignore'
trimTrailingWhitespace()
indentWithSpaces()
endWithNewline()
}
kotlin {
target '**/*.kt'
ktlint()
}
}
repositories {
google()
maven { url 'https://repo.gradle.org/gradle/libs-releases' }
mavenCentral()
}
nexusPublishing {
repositories {
sonatype {
username = System.getProperty('ossrhUsername')
password = System.getProperty('ossrhPassword')
stagingProfileId = System.getProperty('sonatypeStagingProfileId')
useStaging = !isPreRelease
}
}
clientTimeout = Duration.ofSeconds(300)
connectTimeout = Duration.ofSeconds(60)
}
dependencies {
implementation 'com.google.code.gson:gson:2.8.8'
implementation gradleApi()
implementation 'com.android.tools.build:gradle-api:8.3.0'
implementation 'com.android.tools.build:gradle:8.3.0'
implementation 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21'
testImplementation gradleTestKit()
testImplementation 'junit:junit:4.13.2'
testImplementation 'com.google.truth:truth:1.1.3'
testImplementation 'pl.pragmatists:JUnitParams:1.1.1'
}
apply plugin: 'maven-publish'
apply plugin: 'signing'
tasks.register("sourcesJar", Jar).configure {
group = JavaBasePlugin.DOCUMENTATION_GROUP
description = "Assembles sources JAR"
archiveClassifier.set("sources")
from(sourceSets["main"].allSource)
}
tasks.register("javadocJar", Jar).configure {
group = JavaBasePlugin.DOCUMENTATION_GROUP
description = "Assembles javadoc JAR"
archiveClassifier.set("javadoc")
}
publishing {
publications {
apkscaleRelease(MavenPublication) {
groupId = "com.twilio"
artifactId = 'apkscale'
version = getVersionName()
from components.kotlin
artifact(sourcesJar)
artifact(javadocJar)
pom {
name = 'Apkscale'
description = 'A tool to measure the app size impact of Android libraries'
url = 'https://github.com/twilio/apkscale'
scm {
url = 'https://github.com/twilio/apkscale'
connection = 'scm:git:git://github.com/twilio/apkscale.git'
developerConnection = 'scm:git:ssh://[email protected]/twilio/apkscale.git'
tag = 'HEAD'
}
issueManagement {
system = 'GitHub Issues'
url = 'https://github.com/twilio/apkscale/issues'
}
licenses {
license {
name = 'Apache 2.0'
url = 'https://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id = 'Twilio'
name = 'Twilio'
}
}
organization {
name = 'Twilio, Inc.'
url = 'https://www.twilio.com'
}
}
}
}
}
signing {
sign publishing.publications
}
/*
* Checks if release tag matches version and current commit
*/
def matchesVersion(versionTag) {
def properties = new Properties()
file("${rootDir}/gradle.properties").withInputStream { properties.load(it) }
def releaseTag = "${properties.getProperty("versionMajor")}." +
"${properties.getProperty("versionMinor")}." +
"${properties.getProperty("versionPatch")}"
return releaseTag == versionTag
}
task validateReleaseTag {
description = 'Validate the release tag matches the release version present on commit'
doLast {
def circleTag = System.getenv("CIRCLE_TAG")
def tagsMatch = (matchesVersion(circleTag) || isPreRelease) ? ("true") : ("false")
exec {
workingDir "${rootDir}"
commandLine tagsMatch
}
}
}
afterEvaluate {
tasks.findByName("publishApkscaleReleasePublicationToSonatypeRepository").mustRunAfter("validateReleaseTag")
tasks.findByName("publishApkscaleReleasePublicationToSonatypeRepository").dependsOn("validateReleaseTag")
tasks.findByName("closeAndReleaseSonatypeStagingRepository").mustRunAfter("publishApkscaleReleasePublicationToSonatypeRepository")
tasks.findByName("closeAndReleaseSonatypeStagingRepository").dependsOn("publishApkscaleReleasePublicationToSonatypeRepository")
}
task incrementVersion() {
description = 'Increment the version after a release'
doLast {
def stdOut = new ByteArrayOutputStream()
exec {
commandLine "bash", "-c", "git remote show origin | grep HEAD | cut -d: -f2-"
standardOutput stdOut
}
def gitBranch = stdOut.toString().replaceAll("\\s","")
def circleTag = System.getenv("CIRCLE_TAG")
def nextVersionPatch = versionPatch.toInteger() + 1
if (!buildDir.exists()) {
buildDir.mkdir()
}
exec {
workingDir "${rootDir}"
commandLine "git", "checkout", "${gitBranch}"
}
/*
* Only update the version on upstream branch if the version matches tag. It is possible
* these values do not match if a job is performed on an earlier commit and a PR
* with a version update occurs later in history.
*/
if (matchesVersion(circleTag)) {
exec {
workingDir "${rootDir}"
commandLine "echo", "Incrementing from versionPatch ${versionPatch} to " +
"${nextVersionPatch}"
}
exec {
workingDir "${rootDir}"
commandLine "sed",
"s@versionPatch=.*@versionPatch=${nextVersionPatch}@",
"gradle.properties"
standardOutput new FileOutputStream("${buildDir}/gradle.properties")
}
exec {
workingDir "${rootDir}"
commandLine "mv", "${buildDir}/gradle.properties", "gradle.properties"
}
exec {
workingDir "${rootDir}"
commandLine "git", "commit", "gradle.properties", "-m", "\"Bump patch version\""
}
exec {
workingDir "${rootDir}"
commandLine "git", "push", "origin", "${gitBranch}"
}
}
}
}