-
Notifications
You must be signed in to change notification settings - Fork 79
/
build.gradle.kts
489 lines (410 loc) · 15.9 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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage
import com.bmuschko.gradle.docker.tasks.image.Dockerfile
import com.github.jengelman.gradle.plugins.shadow.ShadowJavaPlugin.SHADOW_GROUP
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import com.palantir.gradle.gitversion.VersionDetails
import de.undercouch.gradle.tasks.download.Download
import groovy.lang.Closure
import org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
import org.jetbrains.kotlin.daemon.common.trimQuotes
import org.jetbrains.kotlin.gradle.internal.ensureParentDirsCreated
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import proguard.gradle.ProGuardTask
import java.net.InetAddress
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("com.guardsquare:proguard-gradle:7.2.2") {
exclude("com.android.tools.build", "gradle")
}
}
}
gradle.startParameter.excludedTaskNames += listOf(
"assembleDist",
"assembleShadowDist",
"distTar",
"distZip",
"installDist",
"installShadowDist",
"shadowDistTar",
"shadowDistZip"
)
plugins {
`java-library`
application
`maven-publish`
kotlin("jvm") version "1.7.10"
id("com.palantir.git-version") version "0.15.0"
id("com.github.johnrengelman.shadow") version "7.1.2"
id("com.bmuschko.docker-java-application") version "7.4.0"
id("de.undercouch.download") version "5.1.0"
}
val miRepoAccessKeyId: String? by project
val miRepoSecretAccessKey: String? by project
val miRepoSessionToken: String? by project
val productionBuild: Boolean? by project
val versionDetails: Closure<VersionDetails> by extra
val gitDetails = versionDetails()
fun boolProperty(name: String): Boolean {
return ((properties[name] as String?) ?: "false").toBoolean()
}
val isMiCi = boolProperty("mi-ci")
val isRelease = boolProperty("mi-release")
val longTests: String? by project
val miCiStage = properties["mi-ci-stage"] as String?
group = "com.milaboratory"
version = if (version != "unspecified") version else ""
description = "MiXCR"
java {
sourceCompatibility = JavaVersion.VERSION_11
withSourcesJar()
withJavadocJar()
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "11"
}
application {
mainClass.set("com.milaboratory.mixcr.cli.Main")
applicationDefaultJvmArgs = listOf("-Xmx8g", "-XX:+HeapDumpOnOutOfMemoryError")
}
tasks.withType<JavaExec> {
if (project.hasProperty("runWorkingDir")) {
val runWorkingDir: String by project
workingDir = file(runWorkingDir)
}
systemProperty("mixcr.command", "mixcr")
}
tasks.jar {
manifest {
attributes("Main-Class" to "com.milaboratory.mixcr.cli.Main")
}
}
tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
}
tasks.withType<Javadoc> {
enabled = false
// options {
// this as StandardJavadocDocletOptions
// addStringOption("Xdoclint:none", "-quiet")
// }
}
repositories {
// mavenLocal()
mavenCentral()
maven {
url = uri("s3://milaboratory-artefacts-private-files.s3.eu-central-1.amazonaws.com/maven")
authentication {
credentials(AwsCredentials::class) {
accessKey = miRepoAccessKeyId
secretKey = miRepoSecretAccessKey
sessionToken = miRepoSessionToken
}
}
}
}
val toObfuscate: Configuration by configurations.creating {
@Suppress("UnstableApiUsage")
shouldResolveConsistentlyWith(configurations.runtimeClasspath.get())
}
val obfuscationLibs: Configuration by configurations.creating
val mixcrAlgoVersion = "4.7.0-35-exports-for-trees"
// may be blank (will be inherited from mixcr-algo)
val milibVersion = ""
// may be blank (will be inherited from mixcr-algo or milib)
val miuVersion = ""
// may be blank (will be inherited from mixcr-algo)
val mitoolVersion = "2.3.0-17-mitool-tag-types"
// may be blank (will be inherited from mixcr-algo)
val repseqioVersion = ""
val picocliVersion = "4.6.3"
val jacksonBomVersion = "2.16.0"
val milmVersion = "4.2.0"
val cliktVersion = "3.5.0"
val jcommanderVersion = "1.72"
dependencies {
api("com.milaboratory:mixcr-algo:$mixcrAlgoVersion") {
if (milibVersion.isNotBlank()) {
// prefer miu version from milib
exclude("com.milaboratory", "miu")
}
}
api("com.milaboratory:mitool:$mitoolVersion") {
exclude("com.milaboratory", "milib")
exclude("com.milaboratory", "miu")
}
api("io.repseq:repseqio:$repseqioVersion") {
exclude("com.milaboratory", "milib")
exclude("com.milaboratory", "miu")
}
api("com.milaboratory:milib:$milibVersion")
api("com.milaboratory:miu:$miuVersion")
toObfuscate("com.milaboratory:mixcr-algo") { exclude("*", "*") }
toObfuscate("com.milaboratory:milib") { exclude("*", "*") }
toObfuscate("com.milaboratory:mitool") { exclude("*", "*") }
toObfuscate("io.repseq:repseqio") { exclude("*", "*") }
toObfuscate("com.milaboratory:milm2-jvm") { exclude("*", "*") }
// required for call mitool
implementation("com.github.ajalt.clikt:clikt:$cliktVersion")
// required for buildLibrary (to call repseqio)
implementation("com.beust:jcommander:$jcommanderVersion")
implementation("com.milaboratory:milm2-jvm:$milmVersion")
implementation(platform("com.fasterxml.jackson:jackson-bom:$jacksonBomVersion"))
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("info.picocli:picocli:$picocliVersion")
// // this way dependency will not be transient, but will be included in application
// compileOnly("info.picocli:picocli:$picocliVersion")
// shadow("info.picocli:picocli:$picocliVersion")
// testImplementation("info.picocli:picocli:$picocliVersion")
implementation("net.sf.trove4j:trove4j:3.0.3")
implementation("com.github.victools:jsonschema-generator:4.27.0")
implementation("com.github.victools:jsonschema-module-jackson:4.27.0")
implementation("org.lz4:lz4-java:1.8.0")
shadow("org.apache.logging.log4j:log4j-core:2.20.0")
testImplementation("org.apache.logging.log4j:log4j-core:2.20.0")
testImplementation("junit:junit:4.13.2")
testImplementation(testFixtures("com.milaboratory:milib:$milibVersion"))
testImplementation("org.mockito:mockito-all:1.10.19")
testImplementation("io.kotest:kotest-assertions-core:5.3.0")
// for working reflection scanning
testImplementation("com.github.ajalt.clikt:clikt:$cliktVersion")
testImplementation("com.beust:jcommander:$jcommanderVersion")
testImplementation("org.reflections:reflections:0.10.2")
}
val obfuscateRuntime: Configuration by configurations.creating {
fun ResolvedModuleVersion.asMap() = mapOf(
"group" to id.group,
"name" to id.name,
"version" to id.version
)
defaultDependencies {
val toExclude = toObfuscate.resolvedConfiguration.resolvedArtifacts
.map { it.moduleVersion.id.group to it.moduleVersion.id.name }
.toSet()
configurations.runtimeClasspath.get().resolvedConfiguration.resolvedArtifacts
.filterNot { (it.moduleVersion.id.group to it.moduleVersion.id.name) in toExclude }
.forEach {
add(
project.dependencies.create(it.moduleVersion.asMap())
)
}
}
}
val writeBuildProperties by tasks.registering(WriteProperties::class) {
group = "build"
outputFile = file("${sourceSets.main.get().output.resourcesDir}/${project.name}-build.properties")
property("version", version)
property("name", "MiXCR")
property("revision", gitDetails.gitHash)
property("branch", gitDetails.branchName ?: "no_branch")
property("host", InetAddress.getLocalHost().hostName)
property("production", productionBuild == true)
property("timestamp", if (isMiCi) System.currentTimeMillis() else 0L)
}
val unzipOldPresets by tasks.registering(Copy::class) {
val outputDir = sourceSets.main.get().output.resourcesDir!!.resolve("presets/old_version")
doFirst {
outputDir.deleteRecursively()
outputDir.mkdirs()
}
val archives = projectDir.resolve("old_presets").listFiles()!!
archives.forEach { archive ->
from(tarTree(archive))
into(outputDir)
}
}
val generatePresetFileList by tasks.registering {
group = "build"
val outputFile = sourceSets.main.get().output.resourcesDir!!.resolve("presets/file_list.txt")
doLast {
val source = sourceSets.main.get().output.resourcesDir!!.resolve("presets")
val yamls = layout.files({
source.walk()
.filter { it.extension == "yaml" }
.toList()
})
outputFile.ensureParentDirsCreated()
outputFile.writeText(
yamls
.flatMap { file ->
val presetNames = mutableListOf<String>()
val deprecatedPresets = mutableSetOf<String>()
val abstractPresets = mutableSetOf<String>()
file.useLines { lines ->
for (line in lines) {
if (!line.startsWith(" ") && line.isNotBlank() && !line.startsWith("#")) {
presetNames += line.removeSuffix(":").trimQuotes()
}
if (line.startsWith(" deprecation:") || line.startsWith(" \"deprecation\":")) {
deprecatedPresets += presetNames.last()
}
if (line == " abstract: true" || line == " \"abstract\": true") {
abstractPresets += presetNames.last()
}
}
}
presetNames.map { name ->
val pathToSave = relativePath(file.relativeTo(source))
listOf(
name,
(name in deprecatedPresets).toString(),
(name in abstractPresets).toString(),
pathToSave
)
}
}
.sortedBy { (name) -> name }
.joinToString("\n") { line -> line.joinToString("\t") }
)
}
}
tasks.processResources {
dependsOn(unzipOldPresets)
dependsOn(writeBuildProperties)
finalizedBy(generatePresetFileList)
}
val checkObfuscation by tasks.registering(Test::class) {
group = "build"
testClassesDirs = sourceSets["test"].output.classesDirs
classpath = sourceSets["test"].runtimeClasspath
include("**/MetaForObfuscationTest*")
useJUnit()
}
val obfuscate by tasks.registering(ProGuardTask::class) {
dependsOn(checkObfuscation)
group = "build"
configuration("mixcr.pro")
dependsOn(tasks.jar)
dependsOn(obfuscateRuntime.buildDependencies)
injars(tasks.jar)
injars(toObfuscate)
libraryjars(obfuscateRuntime)
libraryjars(configurations.shadow)
libraryjars(obfuscationLibs)
outjars(buildDir.resolve("libs/mixcr-obfuscated.jar"))
printconfiguration(buildDir.resolve("proguard.config.pro"))
printmapping(buildDir.resolve("proguard-mapping.txt"))
if (org.gradle.internal.jvm.Jvm.current().jre == null)
listOf("java.base.jmod", "java.prefs.jmod", "java.scripting.jmod").map {
libraryjars(
hashMapOf("jarfilter" to "!**.jar", "filter" to "!module-info.class"),
org.gradle.internal.jvm.Jvm.current().javaHome.resolve("jmods/${it}").absolutePath
)
}
else
listOf("rt.jar", "jce.jar", "jsse.jar").map {
libraryjars(org.gradle.internal.jvm.Jvm.current().jre!!.resolve("lib/${it}"))
}
}
val shadowJarAfterObfuscation by tasks.creating(ShadowJar::class) {
group = SHADOW_GROUP
description = "Create a combined JAR of obfuscated project and runtime dependencies"
manifest.inheritFrom(tasks.jar.get().manifest)
dependsOn(obfuscate)
from(obfuscate.get().outJarFiles)
archiveClassifier.set("all")
// copy from com/github/jengelman/gradle/plugins/shadow/ShadowJavaPlugin.groovy:86
exclude("META-INF/INDEX.LIST", "META-INF/*.SF", "META-INF/*.DSA", "META-INF/*.RSA", "module-info.class")
configurations = listOf(obfuscateRuntime, project.configurations.shadow.get())
}
tasks.named<ShadowJar>("shadowJar") {
configurations += project.configurations.shadow.get()
}
val distributionZip by tasks.registering(Zip::class) {
group = "distribution"
archiveFileName.set("${project.name}.zip")
destinationDirectory.set(file("$buildDir/distributions"))
from(shadowJarAfterObfuscation) {
rename("-.*\\.jar", "\\.jar")
}
from("${project.rootDir}/${project.name}")
from("${project.rootDir}/LICENSE")
}
val prepareDockerContext by tasks.registering(Copy::class) {
group = "docker"
from(shadowJarAfterObfuscation) {
rename("-.*\\.jar", "\\.jar")
}
from("${project.rootDir}/${project.name}")
from("${project.rootDir}/LICENSE")
into(layout.buildDirectory.dir("docker"))
}
val prepareIMGTDockerContext by tasks.registering(Download::class) {
group = "docker"
dependsOn(prepareDockerContext)
src("https://github.com/repseqio/library-imgt/releases/download/v8/imgt.202214-2.sv8.json.gz")
dest(layout.buildDirectory.dir("docker"))
}
val commonDockerContents: Dockerfile.() -> Unit = {
from("amazoncorretto:17")
label(mapOf("maintainer" to "MiLaboratories Inc <[email protected]>"))
runCommand("mkdir /work /opt/${project.name}")
runCommand("yum install procps -y") // Needed for image compatibility with nextflow
workingDir("/work")
environmentVariable("PATH", "/opt/${project.name}:\${PATH}")
copyFile("LICENSE", "/opt/${project.name}/LICENSE")
copyFile(project.name, "/opt/${project.name}/${project.name}")
copyFile("${project.name}.jar", "/opt/${project.name}/${project.name}.jar")
}
val createDockerfile by tasks.registering(Dockerfile::class) {
group = "docker"
dependsOn(prepareDockerContext)
commonDockerContents()
}
val imgtDockerfile = layout.buildDirectory.file("docker/Dockerfile.imgt")
val createIMGTDockerfile by tasks.registering(Dockerfile::class) {
group = "docker"
dependsOn(createDockerfile)
dependsOn(prepareIMGTDockerContext)
destFile.set(imgtDockerfile)
commonDockerContents()
copyFile("imgt*", "/opt/${project.name}/")
}
val buildDockerImage by tasks.registering(DockerBuildImage::class) {
group = "docker"
dependsOn(createDockerfile)
images.set(setOf(project.name) + if (version == "") emptySet() else setOf("${project.name}:${version}"))
}
val buildIMGTDockerImage by tasks.registering(DockerBuildImage::class) {
group = "docker"
dependsOn(createIMGTDockerfile)
dockerFile.set(imgtDockerfile)
images.set(setOf(project.name + ":latest-imgt") + if (version == "") emptySet() else setOf("${project.name}:${version}-imgt"))
}
publishing {
repositories {
if (miRepoAccessKeyId != null && miRepoSecretAccessKey != null) {
maven {
name = "mipriv"
url = uri("s3://milaboratory-artefacts-private-files.s3.eu-central-1.amazonaws.com/maven")
authentication {
credentials(AwsCredentials::class) {
accessKey = miRepoAccessKeyId!!
secretKey = miRepoSecretAccessKey!!
sessionToken = miRepoSessionToken
}
}
}
}
}
publications.create<MavenPublication>("mavenJava") {
from(components["java"])
}
}
tasks.test {
useJUnit()
minHeapSize = "1024m"
maxHeapSize = "2048m"
testLogging {
showStandardStreams = true
exceptionFormat = FULL
}
miCiStage?.let {
if (it == "test") {
systemProperty("longTests", "true")
}
}
longTests?.let { systemProperty("longTests", it) }
}