-
Notifications
You must be signed in to change notification settings - Fork 118
/
Copy pathbuild.gradle.kts
359 lines (312 loc) · 11.1 KB
/
build.gradle.kts
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import groovy.util.Node
import groovy.util.NodeList
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.io.ByteArrayOutputStream
plugins {
application
jacoco
kotlin(Plugins.Kotlin.PLUGIN_JVM)
id(Plugins.MAVEN_PUBLISH)
signing
id(Plugins.PLUGIN_SHADOW_JAR) version Versions.SHADOW
id(Plugins.MAVEN_VERSION_CHECK)
}
val artifactID = "flank"
val shadowJar: ShadowJar by tasks
shadowJar.apply {
outputs.cacheIf { false } // to investigate if better solution is possible
archiveClassifier.set("")
archiveBaseName.set(artifactID)
mergeServiceFiles()
minimize {
exclude(dependency(Dependencies.KOTLIN_REFLECT))
exclude(dependency(Dependencies.JACKSON_XML))
exclude(dependency(Dependencies.JACKSON_DATABIND))
exclude(dependency(Dependencies.JACKSON_KOTLIN))
exclude(dependency(Dependencies.JACKSON_YAML))
exclude(dependency(Dependencies.GSON))
}
@Suppress("UnstableApiUsage")
manifest {
attributes(mapOf("Main-Class" to "ftl.Main"))
}
dependencies {
exclude(dependency(Dependencies.TRUTH))
exclude(dependency(Dependencies.MOCKK))
exclude(dependency(Dependencies.JUNIT))
exclude(dependency(Dependencies.PROGUARD))
}
}
java {
withJavadocJar()
withSourcesJar()
}
publishing {
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/Flank/flank")
credentials {
username = System.getenv("GITHUB_ACTOR") ?: properties["GITHUB_ACTOR"].toString()
password = System.getenv("GITHUB_TOKEN") ?: properties["GITHUB_TOKEN"].toString()
}
}
maven {
val staging = "https://oss.sonatype.org/service/local/staging/deploy/maven2"
val snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots"
val version = System.getenv("MVN_VERSION") ?: "local-SNAPSHOT"
url = uri(if (version.endsWith("-SNAPSHOT")) snapshotsRepoUrl else staging)
name = "MavenCentral"
credentials {
username = System.getenv("MVN_CENTRAL_USER") ?: properties["MVN_CENTRAL_USER"].toString()
password = System.getenv("MVN_CENTRAL_PASSWORD") ?: properties["MVN_CENTRAL_PASSWORD"].toString()
}
}
}
publications {
create<MavenPublication>("mavenJava") {
groupId = "com.github.flank"
artifactId = artifactID
version = System.getenv("MVN_VERSION") ?: "local-SNAPSHOT"
artifact(shadowJar)
artifact(tasks["javadocJar"])
artifact(tasks["sourcesJar"])
pom {
name.set("Flank")
description.set("Massively parallel Android and iOS test runner for Firebase Test Lab")
url.set("https://github.com/flank/flank")
licenses {
license {
name.set("The Apache License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
developers {
developer {
id.set("Firebase Test Lab")
name.set("Firebase Test Lab")
email.set("firebase-test-lab-team@google.com")
}
}
scm {
connection.set("scm:git:git://github.com/flank/flank.git")
developerConnection.set("scm:git:ssh://github.com:flank/flank.git")
url.set("https://github.com/flank/flank")
}
}
pom.withXml {
// Remove deps since we're publishing a fat jar
val pom = asNode()
val depNode: NodeList = pom.get("dependencies") as NodeList
for (child in depNode) {
pom.remove(child as Node)
}
}
}
}
}
signing {
val pgpSigningKey: String = System.getenv("PGP_SIGNING_KEY") ?: properties["PGP_SIGNING_KEY"].toString()
useInMemoryPgpKeys(pgpSigningKey, "")
sign(publishing.publications["mavenJava"])
}
// http://www.eclemma.org/jacoco/
jacoco {
toolVersion = "0.8.7"
}
tasks.jacocoTestReport {
classDirectories.setFrom(
fileTree("build/classes/kotlin/main").apply {
exclude("**/*\$run$1.class")
exclude("**/ftl/mock/*")
}
)
reports {
xml.isEnabled = true
html.isEnabled = true
}
}
val runningOnCI get() = System.getenv("CI") != null
// TODO: Fix Java/Kotlin deprecation warnings.
// tasks.withType<KotlinCompile>().configureEach {
// kotlinOptions.allWarningsAsErrors = runningOnCI
// }
application {
// unfortunately shadowJar task seems not to be working correctly with new property based approach
mainClassName = "ftl.Main"
}
repositories {
mavenCentral()
}
// Output full test results to console
// Avoids having to read the HTML report
tasks.withType<Test> {
testLogging {
events("skipped", "failed")
exceptionFormat = TestExceptionFormat.FULL
}
}
dependencies {
implementation(project(Modules.COMMON))
implementation(Dependencies.DD_PLIST)
implementation(Dependencies.DEX_TEST_PARSER)
implementation(Dependencies.JACKSON_KOTLIN)
implementation(Dependencies.JACKSON_YAML)
implementation(Dependencies.JACKSON_XML)
implementation(Dependencies.GOOGLE_NIO)
implementation(Dependencies.GOOGLE_AUTH)
implementation(Dependencies.GOOGLE_STORAGE)
implementation(Dependencies.GOOGLE_TOOLRESULTS)
implementation(Dependencies.KTOR_SERVER_CORE)
implementation(Dependencies.KTOR_SERVER_NETTY)
implementation(Dependencies.KTOR_GSON)
implementation(Dependencies.KOTLIN_COROUTINES_CORE)
implementation(Dependencies.KOTLIN_REFLECT)
implementation(Dependencies.LOGBACK)
implementation(Dependencies.JBOSS_LOGGING)
implementation(Dependencies.PICOCLI)
annotationProcessor(Dependencies.PICOCLI_CODEGEN)
implementation(Dependencies.KOTLIN_LOGGING)
implementation(Dependencies.COMMON_TEXT)
implementation(Dependencies.JANSI)
// NOTE: iOS support isn't in the public artifact. Use testing jar generated from the private gcloud CLI json
// https://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.google.apis%22%20AND%20a%3A%22google-api-services-testing%22
// compile("com.google.apis:google-api-services-testing:v1-rev30-1.23.0")
implementation(project(":firebase_apis:test_api"))
implementation(project(":tool:resource"))
testImplementation(Dependencies.JUNIT)
testImplementation(Dependencies.SYSTEM_RULES)
testImplementation(Dependencies.TRUTH)
testImplementation(Dependencies.MOCKK)
testImplementation(Dependencies.KOTLIN_COROUTINES_TEST)
}
buildscript {
repositories {
mavenLocal()
google()
}
dependencies {
classpath(Dependencies.PROGUARD)
}
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
kotlinOptions.freeCompilerArgs += listOf(
"-Xopt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
"-Xopt-in=kotlinx.coroutines.FlowPreview",
)
}
// https://github.com/gradle/kotlin-dsl/blob/master/samples/task-dependencies/build.gradle.kts#L41
val updateFlank by tasks.registering(Exec::class) {
group = "Build"
description = "Update flank jar"
commandLine = if (System.getProperty("os.name").toLowerCase().contains("windows")) {
doLast {
copy { // due to security permissions copying files is restricted via bat files
from("./test_runner/build/libs/flank.jar")
into("./test_runner/bash/")
}
}
listOf("./bash/update_flank.bat")
} else {
listOf("./bash/update_flank.sh")
}
}
val flankFullRun by tasks.registering(Exec::class) {
dependsOn(tasks["clean"], tasks["check"])
// currently IT run only on CI, implement support to enable local run
dependsOn(":integration_tests:test")
group = "Build"
description = "Perform full test_runner run"
commandLine = listOf("./bash/update_flank.sh")
}
tasks.create("applyProguard", proguard.gradle.ProGuardTask::class.java) {
dependsOn("updateFlank")
description = "Apply proguard to flank and create a minimized jar"
dontwarn()
injars("./build/libs/flank.jar")
outjars("./build/libs/flank-proguard.jar")
libraryjars("${System.getProperty("java.home")}/lib/rt.jar")
libraryjars("./build/libs/flank-sources.jar")
configuration("./proguard/config.pro")
doLast {
copy {
from(file("$buildDir/libs/flank-proguard.jar"))
into(file("./bash/"))
}
}
}
// begin --- ASCII doc generation ---
val generateCliAsciiDoc by tasks.registering(JavaExec::class) {
dependsOn(tasks.classes)
configurations.implementation.configure {
isCanBeResolved = true
}
classpath(
configurations.implementation,
configurations.annotationProcessor,
sourceSets["main"].runtimeClasspath
)
group = "Documentation"
description = "Generate AsciiDoc manpage"
main = "picocli.codegen.docgen.manpage.ManPageGenerator"
args = listOf(
"ftl.presentation.cli.MainCommand",
"--outdir=${project.rootDir}/docs/ascii/",
"-v"
)
}
val processCliAsciiDoc by tasks.registering {
dependsOn(generateCliAsciiDoc)
group = "Documentation"
doLast {
File("${project.rootDir}/docs/ascii").listFiles()?.forEach { file ->
file.apply {
readLines().run {
val toRemove = IntRange(
indexOf("// tag::picocli-generated-man-section-header[]"),
indexOf("// end::picocli-generated-man-section-header[]")
)
filterIndexed { index, _ -> index !in toRemove }
}.joinToString("\n").let { text ->
writeText(text)
}
}
}
}
}
// tasks.assemble {
// dependsOn(processCliAsciiDoc)
// }
// end --- ASCII doc generation ---
val updateVersion by tasks.registering {
shouldRunAfter(tasks.processResources)
if (!runningOnCI) doLast {
File("$buildDir/resources/main/version.txt").writeText("local_snapshot")
File("$buildDir/resources/main/revision.txt").writeText(execAndGetStdout("git", "rev-parse", "HEAD"))
}
}
tasks.classes {
dependsOn(updateVersion)
}
fun execAndGetStdout(vararg args: String): String {
val stdout = ByteArrayOutputStream()
exec {
commandLine(*args)
standardOutput = stdout
workingDir = projectDir
}
return stdout.toString().trimEnd()
}
tasks.test {
maxHeapSize = "3072m"
minHeapSize = "512m"
dependsOn(":resolveArtifacts")
// deletes 'results' directory which contains remainings from unit tests
// think about better solution
doLast {
project.delete("results")
}
}