-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
138 lines (112 loc) · 3.92 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
/*
* Copyright 2023 Dotanuki Labs
* SPDX-License-Identifier: MIT
*/
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jlleitschuh.gradle.ktlint.KtlintExtension
import java.util.Properties
plugins {
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.kotlinx.serialization)
alias(libs.plugins.ktlint)
alias(libs.plugins.detekt)
alias(libs.plugins.shadow)
alias(libs.plugins.test.logger)
}
// ------------------------------------------------------------------
// Attributes
// ------------------------------------------------------------------
group = "io.dotanuki"
version = evaluateVersion()
// ------------------------------------------------------------------
// Plugins
// ------------------------------------------------------------------
kotlin {
jvmToolchain(11)
}
detekt {
buildUponDefaultConfig = true
config.setFrom("$rootDir/detekt.yml")
}
configure<KtlintExtension> {
filter {
exclude { element -> element.file.path.contains("generated/") }
}
}
// ------------------------------------------------------------------
// Dependencies
// ------------------------------------------------------------------
repositories {
mavenCentral()
google()
}
dependencies {
implementation(libs.ajalt.clikt)
implementation(libs.ajalt.mordant)
implementation(libs.arrow.core)
implementation(libs.android.tools.apkanalyzer)
implementation(libs.android.tools.binaryresources)
implementation(libs.android.tools.common)
implementation(libs.android.tools.repository)
implementation(libs.android.tools.sdkcommon)
implementation(libs.android.tools.bundletool)
implementation(libs.android.tools.sdklib)
implementation(libs.kotlinx.serialization.core)
implementation(libs.kotlinx.serialization.jvm)
implementation(libs.kotlinx.serialization.json)
implementation(libs.peanutz.tomlkt)
// Test only
testImplementation(libs.junit)
testImplementation(libs.google.guava)
testImplementation(libs.google.truth)
}
// ------------------------------------------------------------------
// Tasks
// ------------------------------------------------------------------
tasks.withType<KotlinCompile>().configureEach {
compilerOptions.freeCompilerArgs.set(
listOf("-Xcontext-receivers"),
)
}
tasks.withType<ShadowJar>().configureEach {
manifest {
attributes["Add-Opens"] = "java.base/java.lang.invoke"
attributes["Main-Class"] = "io.dotanuki.aaw.MainKt"
archiveFileName.set("aaw-$version.jar")
}
}
val assembleExecutable by tasks.registering(DefaultTask::class) {
description = "Creates an executable standalone binary for this project"
group = "Build"
dependsOn(tasks.shadowJar)
val aawShadowJarFile =
tasks.shadowJar.orNull?.outputs?.files?.singleFile
?: throw GradleException("Missing aaw shadowJar file")
inputs.files(aawShadowJarFile)
val outputDirectoryPath = "${layout.buildDirectory.get()}/bin"
val executableOutputPath = "$outputDirectoryPath/aaw"
outputs.files(executableOutputPath)
doLast {
File(executableOutputPath).apply {
logger.lifecycle("Creating the self-executable file: $outputDirectoryPath")
writeText(
"""
#! /usr/bin/env bash
exec java -Xmx1024m -jar "$0" "$@"
""".trimIndent(),
)
appendBytes(aawShadowJarFile.readBytes())
setExecutable(true, false)
}
}
}
// ------------------------------------------------------------------
// Other helpers
// ------------------------------------------------------------------
fun evaluateVersion(): String =
File("$rootDir/src/main/resources/versions.properties")
.inputStream()
.use { stream ->
Properties().apply { load(stream) }["latest"].toString()
}