-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
158 lines (136 loc) · 4.54 KB
/
Copy pathbuild.gradle.kts
File metadata and controls
158 lines (136 loc) · 4.54 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
import java.io.ByteArrayOutputStream
val version = "3.1.0"
val suffix = "SNAPSHOT"
// Strings embedded into the build.
var gitRevision = ""
var apktoolVersion = ""
defaultTasks("build", "shadowJar", "proguard")
require(JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_17)) {
"Building Apktool requires JDK 17 or newer, but Gradle is running on JDK ${JavaVersion.current()}."
}
// Functions
val gitDescribe: String? by lazy {
try {
val result = providers.exec {
commandLine("git", "describe", "--tags")
}
result.standardOutput.asText.get().trim().replace("-g", "-")
} catch (e: Exception) {
null
}
}
val gitBranch: String? by lazy {
try {
val result = providers.exec {
commandLine("git", "rev-parse", "--abbrev-ref", "HEAD")
}
result.standardOutput.asText.get().trim()
} catch (e: Exception) {
null
}
}
if ("release" !in gradle.startParameter.taskNames) {
val hash = gitDescribe
if (hash == null) {
gitRevision = "dirty"
apktoolVersion = "$version-dirty"
project.logger.lifecycle("Building SNAPSHOT (no .git folder found)")
} else {
gitRevision = hash
apktoolVersion = "$hash-SNAPSHOT"
project.logger.lifecycle("Building SNAPSHOT ($gitBranch): $gitRevision")
}
} else {
gitRevision = ""
apktoolVersion = if (suffix.isNotEmpty()) "$version-$suffix" else version;
project.logger.lifecycle("Building RELEASE ($gitBranch): $apktoolVersion")
}
extra.set("gitRevision", gitRevision)
extra.set("apktoolVersion", apktoolVersion)
plugins {
`java-library`
alias(libs.plugins.vanniktech.maven.publish) apply false
}
allprojects {
repositories {
mavenCentral()
// Obtain baksmali/smali from source builds - https://github.com/iBotPeaches/smali
// Remove when official smali releases come out again.
maven {
url = uri("https://jitpack.io")
content {
includeGroup("com.github.iBotPeaches.smali")
}
}
google()
}
}
subprojects {
apply(plugin = "java")
apply(plugin = "java-library")
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
tasks.withType<JavaCompile>().configureEach {
options.encoding = "UTF-8"
// Build with JDK 17, but emit Java 8 compatible bytecode against the Java 8 API.
options.release.set(8)
}
tasks.withType<Test>().configureEach {
val projectName = project.name;
testLogging {
events("failed", "skipped")
}
addTestListener(object : TestListener {
override fun afterSuite(suite: TestDescriptor, result: TestResult) {
if (suite.parent != null) {
return;
}
logger.lifecycle(
"[{}] Tests: {} passed, {} failed, {} skipped (total: {})",
projectName,
result.successfulTestCount,
result.failedTestCount,
result.skippedTestCount,
result.testCount
)
}
})
}
// CI passes -PtestJdkVersion to run the test suite on an older JVM (8/11)
// while the build itself stays on JDK 17.
providers.gradleProperty("testJdkVersion").orNull?.toIntOrNull()?.let { testJdkVersion ->
val toolchains = extensions.getByType<JavaToolchainService>()
tasks.withType<Test>().configureEach {
javaLauncher = toolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(testJdkVersion)
// Zulu ships JDK 8 builds for every OS/arch we test on, including mac arm64.
vendor = JvmVendorSpec.AZUL
}
doFirst {
val launcher = javaLauncher.get()
logger.lifecycle(
"[{}] Test JVM: {} (runtime: {})",
project.name,
launcher.executablePath,
launcher.metadata.javaRuntimeVersion
)
}
}
}
val mavenProjects = arrayOf(
"brut.j.common", "brut.j.util", "brut.j.dir", "brut.j.xml", "brut.j.yaml",
"apktool-lib"
)
if (project.name in mavenProjects) {
apply(from = "${rootProject.projectDir}/gradle/scripts/publishing.gradle")
}
}
tasks.register("release") {
// Used for official releases.
}
tasks.wrapper {
distributionType = Wrapper.DistributionType.ALL
}